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

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: Rebased 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())
sclittle 2015/11/30 22:33:38 nit: It looks like |io_thread| and |io_thread->glo
tbansal1 2015/11/30 22:59:09 Done.
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 #endif // defined(OS_ANDROID)
122
94 } // namespace 123 } // namespace
95 124
96 using content::BrowserThread; 125 using content::BrowserThread;
97 126
98 ProfileImplIOData::Handle::Handle(Profile* profile) 127 ProfileImplIOData::Handle::Handle(Profile* profile)
99 : io_data_(new ProfileImplIOData), 128 : io_data_(new ProfileImplIOData),
100 profile_(profile), 129 profile_(profile),
101 initialized_(false) { 130 initialized_(false) {
102 DCHECK_CURRENTLY_ON(BrowserThread::UI); 131 DCHECK_CURRENTLY_ON(BrowserThread::UI);
103 DCHECK(profile); 132 DCHECK(profile);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 pool->GetSequenceToken(), 221 pool->GetSequenceToken(),
193 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 222 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
194 scoped_ptr<data_reduction_proxy::DataStore> store( 223 scoped_ptr<data_reduction_proxy::DataStore> store(
195 new data_reduction_proxy::DataStoreImpl(profile_path)); 224 new data_reduction_proxy::DataStoreImpl(profile_path));
196 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_) 225 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile_)
197 ->InitDataReductionProxySettings( 226 ->InitDataReductionProxySettings(
198 io_data_->data_reduction_proxy_io_data(), profile_->GetPrefs(), 227 io_data_->data_reduction_proxy_io_data(), profile_->GetPrefs(),
199 profile_->GetRequestContext(), store.Pass(), 228 profile_->GetRequestContext(), store.Pass(),
200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 229 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
201 db_task_runner); 230 db_task_runner);
231
232 #if defined(OS_ANDROID)
233 // Pass the DataUseTabModel weak pointer to DataUseUITabModel, and register
234 // DataUseUITabModel as a DataUseTabModel::TabDataUseObserver.
235 chrome::android::DataUseUITabModel* data_use_ui_tab_model =
236 chrome::android::DataUseUITabModelFactory::GetForBrowserContext(profile_);
237
238 if (data_use_ui_tab_model && !io_data_->IsOffTheRecord()) {
239 BrowserThread::PostTaskAndReplyWithResult(
240 BrowserThread::IO, FROM_HERE,
241 base::Bind(&SetDataUseTabModelOnIOThread,
242 g_browser_process->io_thread(),
243 data_use_ui_tab_model->GetWeakPtr()),
244 base::Bind(&chrome::android::DataUseUITabModel::SetDataUseTabModel,
245 data_use_ui_tab_model->GetWeakPtr()));
246 }
247 #endif // defined(OS_ANDROID)
202 } 248 }
203 249
204 content::ResourceContext* 250 content::ResourceContext*
205 ProfileImplIOData::Handle::GetResourceContext() const { 251 ProfileImplIOData::Handle::GetResourceContext() const {
206 DCHECK_CURRENTLY_ON(BrowserThread::UI); 252 DCHECK_CURRENTLY_ON(BrowserThread::UI);
207 LazyInitialize(); 253 LazyInitialize();
208 return GetResourceContextNoInit(); 254 return GetResourceContextNoInit();
209 } 255 }
210 256
211 content::ResourceContext* 257 content::ResourceContext*
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 const base::Closure& completion) { 829 const base::Closure& completion) {
784 DCHECK_CURRENTLY_ON(BrowserThread::IO); 830 DCHECK_CURRENTLY_ON(BrowserThread::IO);
785 DCHECK(initialized()); 831 DCHECK(initialized());
786 832
787 DCHECK(transport_security_state()); 833 DCHECK(transport_security_state());
788 // Completes synchronously. 834 // Completes synchronously.
789 transport_security_state()->DeleteAllDynamicDataSince(time); 835 transport_security_state()->DeleteAllDynamicDataSince(time);
790 DCHECK(http_server_properties_manager_); 836 DCHECK(http_server_properties_manager_);
791 http_server_properties_manager_->Clear(completion); 837 http_server_properties_manager_->Clear(completion);
792 } 838 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698