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

Side by Side Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 1443683002: Notify DataUseTabModel of navigations and tab closures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profiles/profile_impl_io_data.h" 5 #include "chrome/browser/profiles/profile_impl_io_data.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "net/ftp/ftp_network_layer.h" 58 #include "net/ftp/ftp_network_layer.h"
59 #include "net/http/http_cache.h" 59 #include "net/http/http_cache.h"
60 #include "net/http/http_network_session.h" 60 #include "net/http/http_network_session.h"
61 #include "net/http/http_server_properties_manager.h" 61 #include "net/http/http_server_properties_manager.h"
62 #include "net/sdch/sdch_owner.h" 62 #include "net/sdch/sdch_owner.h"
63 #include "net/ssl/channel_id_service.h" 63 #include "net/ssl/channel_id_service.h"
64 #include "net/url_request/url_request_intercepting_job_factory.h" 64 #include "net/url_request/url_request_intercepting_job_factory.h"
65 #include "net/url_request/url_request_job_factory_impl.h" 65 #include "net/url_request/url_request_job_factory_impl.h"
66 #include "storage/browser/quota/special_storage_policy.h" 66 #include "storage/browser/quota/special_storage_policy.h"
67 67
68 #if defined(OS_ANDROID)
69 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
70 #include "chrome/browser/android/data_usage/data_use_ui_tab_model.h"
71 #include "chrome/browser/android/data_usage/data_use_ui_tab_model_factory.h"
72 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
73 #endif // defined(OS_ANDROID)
74
68 namespace { 75 namespace {
69 76
70 net::BackendType ChooseCacheBackendType() { 77 net::BackendType ChooseCacheBackendType() {
71 #if defined(OS_ANDROID) 78 #if defined(OS_ANDROID)
72 return net::CACHE_BACKEND_SIMPLE; 79 return net::CACHE_BACKEND_SIMPLE;
73 #else 80 #else
74 const base::CommandLine& command_line = 81 const base::CommandLine& command_line =
75 *base::CommandLine::ForCurrentProcess(); 82 *base::CommandLine::ForCurrentProcess();
76 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { 83 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) {
77 const std::string opt_value = 84 const std::string opt_value =
78 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); 85 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend);
79 if (base::LowerCaseEqualsASCII(opt_value, "off")) 86 if (base::LowerCaseEqualsASCII(opt_value, "off"))
80 return net::CACHE_BACKEND_BLOCKFILE; 87 return net::CACHE_BACKEND_BLOCKFILE;
81 if (opt_value.empty() || base::LowerCaseEqualsASCII(opt_value, "on")) 88 if (opt_value.empty() || base::LowerCaseEqualsASCII(opt_value, "on"))
82 return net::CACHE_BACKEND_SIMPLE; 89 return net::CACHE_BACKEND_SIMPLE;
83 } 90 }
84 const std::string experiment_name = 91 const std::string experiment_name =
85 base::FieldTrialList::FindFullName("SimpleCacheTrial"); 92 base::FieldTrialList::FindFullName("SimpleCacheTrial");
86 if (experiment_name == "ExperimentYes" || 93 if (experiment_name == "ExperimentYes" ||
87 experiment_name == "ExperimentYes2") { 94 experiment_name == "ExperimentYes2") {
88 return net::CACHE_BACKEND_SIMPLE; 95 return net::CACHE_BACKEND_SIMPLE;
89 } 96 }
90 return net::CACHE_BACKEND_BLOCKFILE; 97 return net::CACHE_BACKEND_BLOCKFILE;
91 #endif 98 #endif
92 } 99 }
93 100
101 #if defined(OS_ANDROID)
102 // Returns the weak pointer to DataUseTabModel, and adds |data_use_ui_tab_model|
103 // as an observer to DataUseTabModel. Must be called only on IO thread.
104 base::WeakPtr<chrome::android::DataUseTabModel> SetDataUseTabModelOnIOThread(
105 IOThread* io_thread,
106 base::WeakPtr<chrome::android::DataUseUITabModel> data_use_ui_tab_model) {
107 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
108
109 if (!io_thread || !io_thread->globals())
110 return base::WeakPtr<chrome::android::DataUseTabModel>();
111
112 base::WeakPtr<chrome::android::DataUseTabModel> data_use_tab_model =
113 io_thread->globals()
114 ->external_data_use_observer->GetDataUseTabModel()
115 ->GetWeakPtr();
116 if (data_use_tab_model)
117 data_use_tab_model->AddObserver(data_use_ui_tab_model);
118 return data_use_tab_model;
119 }
120
121 // Passes the weak pointer to DataUseTabModel to |data_use_ui_tab_model|. Must
122 // be called only on UI thread.
123 void SetDataUseTabModelOnUIThread(
124 base::WeakPtr<chrome::android::DataUseUITabModel> data_use_ui_tab_model,
125 base::WeakPtr<chrome::android::DataUseTabModel> data_use_tab_model) {
126 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
127 data_use_ui_tab_model->SetDataUseTabModel(data_use_tab_model);
128 }
129 #endif // defined(OS_ANDROID)
130
94 } // namespace 131 } // namespace
95 132
96 using content::BrowserThread; 133 using content::BrowserThread;
97 134
98 ProfileImplIOData::Handle::Handle(Profile* profile) 135 ProfileImplIOData::Handle::Handle(Profile* profile)
99 : io_data_(new ProfileImplIOData), 136 : io_data_(new ProfileImplIOData),
100 profile_(profile), 137 profile_(profile),
101 initialized_(false) { 138 initialized_(false) {
102 DCHECK_CURRENTLY_ON(BrowserThread::UI); 139 DCHECK_CURRENTLY_ON(BrowserThread::UI);
103 DCHECK(profile); 140 DCHECK(profile);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 pool->GetSequenceToken(), 229 pool->GetSequenceToken(),
193 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 230 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
194 scoped_ptr<data_reduction_proxy::DataStore> store( 231 scoped_ptr<data_reduction_proxy::DataStore> store(
195 new data_reduction_proxy::DataStoreImpl(profile_path)); 232 new data_reduction_proxy::DataStoreImpl(profile_path));
196 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_) 233 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_)
197 ->InitDataReductionProxySettings( 234 ->InitDataReductionProxySettings(
198 io_data_->data_reduction_proxy_io_data(), profile_->GetPrefs(), 235 io_data_->data_reduction_proxy_io_data(), profile_->GetPrefs(),
199 profile_->GetRequestContext(), store.Pass(), 236 profile_->GetRequestContext(), store.Pass(),
200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 237 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
201 db_task_runner); 238 db_task_runner);
239
240 #if defined(OS_ANDROID)
241 // Pass the DataUseTabModel weak pointer to DataUseUITabModel, and register
242 // DataUseUITabModel as a DataUseTabModel::TabDataUseObserver.
243 chrome::android::DataUseUITabModel* data_use_ui_tab_model =
244 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile_);
245
246 if (data_use_ui_tab_model && !io_data_->IsOffTheRecord()) {
247 BrowserThread::PostTaskAndReplyWithResult(
248 BrowserThread::IO, FROM_HERE,
249 base::Bind(&SetDataUseTabModelOnIOThread,
250 g_browser_process->io_thread(),
251 data_use_ui_tab_model->GetWeakPtr()),
252 base::Bind(&SetDataUseTabModelOnUIThread,
sclittle 2015/11/25 22:49:11 You could just bind &chrome::android::DataUseUITab
tbansal1 2015/11/26 00:31:21 Done.
253 data_use_ui_tab_model->GetWeakPtr()));
254 }
255 #endif // defined(OS_ANDROID)
202 } 256 }
203 257
204 content::ResourceContext* 258 content::ResourceContext*
205 ProfileImplIOData::Handle::GetResourceContext() const { 259 ProfileImplIOData::Handle::GetResourceContext() const {
206 DCHECK_CURRENTLY_ON(BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
207 LazyInitialize(); 261 LazyInitialize();
208 return GetResourceContextNoInit(); 262 return GetResourceContextNoInit();
209 } 263 }
210 264
211 content::ResourceContext* 265 content::ResourceContext*
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 const base::Closure& completion) { 838 const base::Closure& completion) {
785 DCHECK_CURRENTLY_ON(BrowserThread::IO); 839 DCHECK_CURRENTLY_ON(BrowserThread::IO);
786 DCHECK(initialized()); 840 DCHECK(initialized());
787 841
788 DCHECK(transport_security_state()); 842 DCHECK(transport_security_state());
789 // Completes synchronously. 843 // Completes synchronously.
790 transport_security_state()->DeleteAllDynamicDataSince(time); 844 transport_security_state()->DeleteAllDynamicDataSince(time);
791 DCHECK(http_server_properties_manager_); 845 DCHECK(http_server_properties_manager_);
792 http_server_properties_manager_->Clear(completion); 846 http_server_properties_manager_->Clear(completion);
793 } 847 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698