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

Side by Side Diff: chrome/browser/previews/previews_service.cc

Issue 2739033005: Moving previews code from components/ to chrome/ (Closed)
Patch Set: switch statement Created 3 years, 9 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 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/previews/previews_service.h" 5 #include "chrome/browser/previews/previews_service.h"
6 6
7 #include "base/bind.h"
7 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
8 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
9 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
10 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/common/chrome_constants.h" 12 #include "chrome/common/chrome_constants.h"
13 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
14 #include "components/previews/core/previews_experiments.h"
12 #include "components/previews/core/previews_io_data.h" 15 #include "components/previews/core/previews_io_data.h"
13 #include "components/previews/core/previews_opt_out_store.h" 16 #include "components/previews/core/previews_opt_out_store.h"
14 #include "components/previews/core/previews_opt_out_store_sql.h" 17 #include "components/previews/core/previews_opt_out_store_sql.h"
15 #include "components/previews/core/previews_ui_service.h" 18 #include "components/previews/core/previews_ui_service.h"
16 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
17 20
21 namespace {
22
23 // Returns true if the field trial that should enable previews for |type| for
24 // prohibitvely slow networks is active.
tbansal1 2017/03/10 21:14:53 This comment looks incorrect. Or may be change th
RyanSturm 2017/03/10 22:06:29 Done.
25 bool IsPreviewsTypeEnabled(previews::PreviewsType type) {
26 switch (type) {
27 case previews::PreviewsType::OFFLINE:
28 return previews::params::IsOfflinePreviewsEnabled();
29 case previews::PreviewsType::NONE:
30 case previews::PreviewsType::LAST:
31 break;
32 }
33 NOTREACHED();
34 return false;
35 }
36
37 // Returns the version of preview treatment |type|. Should default to 0 if not
tbansal1 2017/03/10 21:14:53 s/Should default/Defaults/
RyanSturm 2017/03/10 22:06:29 Done.
38 // specified in field trial config.
39 int GetPreviewsTypeVersion(previews::PreviewsType type) {
40 switch (type) {
41 case previews::PreviewsType::OFFLINE:
42 return previews::params::OfflinePreviewsVersion();
43 case previews::PreviewsType::NONE:
44 case previews::PreviewsType::LAST:
45 break;
46 }
47 NOTREACHED();
48 return -1;
49 }
50
51 // Returns the enabled PreviewsTypes with their version.
52 std::unique_ptr<previews::PreviewsTypeList> GetEnabledPreviews() {
53 std::unique_ptr<previews::PreviewsTypeList> enabled_previews(
54 new previews::PreviewsTypeList());
55
56 // Loop across all previews types (relies on sequential enum values).
57 for (int i = static_cast<int>(previews::PreviewsType::NONE) + 1;
58 i < static_cast<int>(previews::PreviewsType::LAST); ++i) {
59 previews::PreviewsType type = static_cast<previews::PreviewsType>(i);
60 if (IsPreviewsTypeEnabled(type)) {
tbansal1 2017/03/10 21:14:53 rm parens.
RyanSturm 2017/03/10 22:06:29 Done.
61 enabled_previews->push_back({type, GetPreviewsTypeVersion(type)});
62 }
63 }
64 return enabled_previews;
65 }
66
67 } // namespace
68
18 PreviewsService::PreviewsService() { 69 PreviewsService::PreviewsService() {
19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
20 } 71 }
21 72
22 PreviewsService::~PreviewsService() { 73 PreviewsService::~PreviewsService() {
23 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 74 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
24 } 75 }
25 76
26 void PreviewsService::Initialize( 77 void PreviewsService::Initialize(
27 previews::PreviewsIOData* previews_io_data, 78 previews::PreviewsIOData* previews_io_data,
28 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 79 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
29 const base::FilePath& profile_path) { 80 const base::FilePath& profile_path) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
31 82
32 base::SequencedWorkerPool* blocking_pool = 83 base::SequencedWorkerPool* blocking_pool =
33 content::BrowserThread::GetBlockingPool(); 84 content::BrowserThread::GetBlockingPool();
34 // Get the background thread to run SQLite on. 85 // Get the background thread to run SQLite on.
35 scoped_refptr<base::SequencedTaskRunner> background_task_runner = 86 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
36 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken()); 87 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken());
37 88
38 previews_ui_service_ = base::MakeUnique<previews::PreviewsUIService>( 89 previews_ui_service_ = base::MakeUnique<previews::PreviewsUIService>(
39 previews_io_data, io_task_runner, 90 previews_io_data, io_task_runner,
40 base::MakeUnique<previews::PreviewsOptOutStoreSQL>( 91 base::MakeUnique<previews::PreviewsOptOutStoreSQL>(
41 io_task_runner, background_task_runner, 92 io_task_runner, background_task_runner,
42 profile_path.Append(chrome::kPreviewsOptOutDBFilename))); 93 profile_path.Append(chrome::kPreviewsOptOutDBFilename),
94 GetEnabledPreviews()),
95 base::Bind(&IsPreviewsTypeEnabled));
43 } 96 }
OLDNEW
« no previous file with comments | « no previous file | components/previews/core/previews_experiments.h » ('j') | components/previews/core/previews_experiments.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698