Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/browser/tracing/chrome_tracing_delegate.cc

Issue 1164023002: Slow Reports: Set a minimum time in between reports, and check for OTR sessions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Buildfixes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/tracing/chrome_tracing_delegate.h" 5 #include "chrome/browser/tracing/chrome_tracing_delegate.h"
6
7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h"
6 #include "chrome/browser/tracing/crash_service_uploader.h" 13 #include "chrome/browser/tracing/crash_service_uploader.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_otr_state.h"
17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/background_tracing_config.h"
19 #include "content/public/browser/browser_thread.h"
20
21 namespace {
22
23 const int kMinDaysUntilNextUpload = 7;
24
25 } // namespace
26
27 void ChromeTracingDelegate::RegisterPrefs(PrefRegistrySimple* registry) {
28 registry->RegisterInt64Pref(prefs::kBackgroundTracingLastUpload, 0);
29 }
30
31 ChromeTracingDelegate::ChromeTracingDelegate() : incognito_launched_(false) {
32 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
33 BrowserList::AddObserver(this);
34 }
35
36 ChromeTracingDelegate::~ChromeTracingDelegate() {
37 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
38 BrowserList::RemoveObserver(this);
39 }
40
41 void ChromeTracingDelegate::OnBrowserAdded(Browser* browser) {
42 if (browser->profile()->IsOffTheRecord())
43 incognito_launched_ = true;
44 }
7 45
8 scoped_ptr<content::TraceUploader> ChromeTracingDelegate::GetTraceUploader( 46 scoped_ptr<content::TraceUploader> ChromeTracingDelegate::GetTraceUploader(
9 net::URLRequestContextGetter* request_context) { 47 net::URLRequestContextGetter* request_context) {
10 return scoped_ptr<content::TraceUploader>( 48 return scoped_ptr<content::TraceUploader>(
11 new TraceCrashServiceUploader(request_context)); 49 new TraceCrashServiceUploader(request_context));
12 } 50 }
51
52 bool ChromeTracingDelegate::IsAllowedToBeginBackgroundScenario(
53 const content::BackgroundTracingConfig& config,
54 bool requires_anonymized_data) {
55 Profile* profile = g_browser_process->profile_manager()
56 ->GetLastUsedProfile()
57 ->GetOriginalProfile();
58 DCHECK(profile);
59 // Safeguard, in case background tracing is responsible for a crash on
60 // startup.
61 if (profile->GetLastSessionExitType() == Profile::EXIT_CRASHED)
62 return false;
63
64 if (requires_anonymized_data && chrome::IsOffTheRecordSessionActive())
65 return false;
66
67 if (config.mode ==
68 content::BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
69 PrefService* local_state = g_browser_process->local_state();
70 DCHECK(local_state);
71 const base::Time last_upload_time = base::Time::FromInternalValue(
72 local_state->GetInt64(prefs::kBackgroundTracingLastUpload));
73 if (!last_upload_time.is_null()) {
74 base::Time computed_next_allowed_time =
75 last_upload_time + base::TimeDelta::FromDays(kMinDaysUntilNextUpload);
76 if (computed_next_allowed_time > base::Time::Now()) {
77 return false;
78 }
79 }
80 }
81
82 return true;
83 }
84
85 bool ChromeTracingDelegate::IsAllowedToEndBackgroundScenario(
86 const content::BackgroundTracingConfig& config,
87 bool requires_anonymized_data) {
88 if (requires_anonymized_data && incognito_launched_)
89 return false;
90
91 if (config.mode ==
92 content::BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
93 PrefService* local_state = g_browser_process->local_state();
94 DCHECK(local_state);
95 local_state->SetInt64(prefs::kBackgroundTracingLastUpload,
96 base::Time::Now().ToInternalValue());
97
98 // We make sure we've persisted the value in case finalizing the tracing
99 // causes a crash.
100 local_state->CommitPendingWrite();
101 }
102
103 return true;
104 }
OLDNEW
« no previous file with comments | « chrome/browser/tracing/chrome_tracing_delegate.h ('k') | chrome/browser/tracing/chrome_tracing_delegate_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698