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

Side by Side Diff: chrome/browser/android/offline_pages/request_coordinator_factory.cc

Issue 2347783003: [OfflinePages, NetworkQualityEstimator] Use NetworkQualityEstimator to decide on triggering Backgro… (Closed)
Patch Set: Addressed feedback Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/net/nqe/ui_network_quality_estimator_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/offline_pages/request_coordinator_factory.h" 5 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.h" 12 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.h"
13 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h" 13 #include "chrome/browser/android/offline_pages/downloads/offline_page_notificati on_bridge.h"
14 #include "chrome/browser/android/offline_pages/prerendering_offliner_factory.h" 14 #include "chrome/browser/android/offline_pages/prerendering_offliner_factory.h"
15 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
16 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_constants.h" 18 #include "chrome/common/chrome_constants.h"
17 #include "components/keyed_service/content/browser_context_dependency_manager.h" 19 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 #include "components/offline_pages/background/offliner_factory.h" 20 #include "components/offline_pages/background/offliner_factory.h"
19 #include "components/offline_pages/background/offliner_policy.h" 21 #include "components/offline_pages/background/offliner_policy.h"
20 #include "components/offline_pages/background/request_coordinator.h" 22 #include "components/offline_pages/background/request_coordinator.h"
21 #include "components/offline_pages/background/request_queue.h" 23 #include "components/offline_pages/background/request_queue.h"
22 #include "components/offline_pages/background/request_queue_store.h" 24 #include "components/offline_pages/background/request_queue_store.h"
23 #include "components/offline_pages/background/request_queue_store_sql.h" 25 #include "components/offline_pages/background/request_queue_store_sql.h"
24 #include "components/offline_pages/background/scheduler.h" 26 #include "components/offline_pages/background/scheduler.h"
25 #include "components/offline_pages/downloads/download_notifying_observer.h" 27 #include "components/offline_pages/downloads/download_notifying_observer.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "net/nqe/network_quality_estimator.h"
27 30
28 namespace offline_pages { 31 namespace offline_pages {
29 32
30 RequestCoordinatorFactory::RequestCoordinatorFactory() 33 RequestCoordinatorFactory::RequestCoordinatorFactory()
31 : BrowserContextKeyedServiceFactory( 34 : BrowserContextKeyedServiceFactory(
32 "OfflineRequestCoordinator", 35 "OfflineRequestCoordinator",
33 BrowserContextDependencyManager::GetInstance()) {} 36 BrowserContextDependencyManager::GetInstance()) {}
34 37
35 // static 38 // static
36 RequestCoordinatorFactory* RequestCoordinatorFactory::GetInstance() { 39 RequestCoordinatorFactory* RequestCoordinatorFactory::GetInstance() {
37 return base::Singleton<RequestCoordinatorFactory>::get(); 40 return base::Singleton<RequestCoordinatorFactory>::get();
38 } 41 }
39 42
40 // static 43 // static
41 RequestCoordinator* RequestCoordinatorFactory::GetForBrowserContext( 44 RequestCoordinator* RequestCoordinatorFactory::GetForBrowserContext(
42 content::BrowserContext* context) { 45 content::BrowserContext* context) {
43 return static_cast<RequestCoordinator*>( 46 return static_cast<RequestCoordinator*>(
44 GetInstance()->GetServiceForBrowserContext(context, true)); 47 GetInstance()->GetServiceForBrowserContext(context, true));
45 } 48 }
46 49
47 KeyedService* RequestCoordinatorFactory::BuildServiceInstanceFor( 50 KeyedService* RequestCoordinatorFactory::BuildServiceInstanceFor(
48 content::BrowserContext* context) const { 51 content::BrowserContext* context) const {
49 std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy()); 52 std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy());
50 std::unique_ptr<OfflinerFactory> prerenderer_offliner( 53 std::unique_ptr<OfflinerFactory> prerenderer_offliner(
51 new PrerenderingOfflinerFactory(context)); 54 new PrerenderingOfflinerFactory(context));
52 55
53 scoped_refptr<base::SequencedTaskRunner> background_task_runner = 56 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
54 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( 57 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
55 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); 58 content::BrowserThread::GetBlockingPool()->GetSequenceToken());
59 Profile* profile = Profile::FromBrowserContext(context);
56 base::FilePath queue_store_path = 60 base::FilePath queue_store_path =
57 Profile::FromBrowserContext(context)->GetPath().Append( 61 profile->GetPath().Append(chrome::kOfflinePageRequestQueueDirname);
58 chrome::kOfflinePageRequestQueueDirname);
59 62
60 std::unique_ptr<RequestQueueStoreSQL> queue_store( 63 std::unique_ptr<RequestQueueStoreSQL> queue_store(
61 new RequestQueueStoreSQL(background_task_runner, queue_store_path)); 64 new RequestQueueStoreSQL(background_task_runner, queue_store_path));
62 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(queue_store))); 65 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(queue_store)));
63 std::unique_ptr<Scheduler> 66 std::unique_ptr<Scheduler>
64 scheduler(new android::BackgroundSchedulerBridge()); 67 scheduler(new android::BackgroundSchedulerBridge());
68 net::NetworkQualityEstimator::NetworkQualityProvider*
69 network_quality_estimator =
70 UINetworkQualityEstimatorServiceFactory::GetForProfile(profile);
65 // TODO(fgorski): Something needs to keep the handle to the Notification 71 // TODO(fgorski): Something needs to keep the handle to the Notification
66 // dispatcher. 72 // dispatcher.
67 RequestCoordinator* request_coordinator = 73 RequestCoordinator* request_coordinator = new RequestCoordinator(
68 new RequestCoordinator(std::move(policy), std::move(prerenderer_offliner), 74 std::move(policy), std::move(prerenderer_offliner), std::move(queue),
69 std::move(queue), std::move(scheduler)); 75 std::move(scheduler), network_quality_estimator);
70 76
71 DownloadNotifyingObserver::CreateAndStartObserving( 77 DownloadNotifyingObserver::CreateAndStartObserving(
72 request_coordinator, 78 request_coordinator,
73 base::MakeUnique<android::OfflinePageNotificationBridge>()); 79 base::MakeUnique<android::OfflinePageNotificationBridge>());
74 80
75 return request_coordinator; 81 return request_coordinator;
76 } 82 }
77 83
78 content::BrowserContext* RequestCoordinatorFactory::GetBrowserContextToUse( 84 content::BrowserContext* RequestCoordinatorFactory::GetBrowserContextToUse(
79 content::BrowserContext* context) const { 85 content::BrowserContext* context) const {
80 // TODO(petewil): Make sure we support incognito properly. 86 // TODO(petewil): Make sure we support incognito properly.
81 return context; 87 return context;
82 } 88 }
83 89
84 } // namespace offline_pages 90 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/nqe/ui_network_quality_estimator_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698