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

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

Issue 2739033005: Moving previews code from components/ to chrome/ (Closed)
Patch Set: tbansal nits 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"
tbansal1 2017/03/10 23:06:23 rm this include?
RyanSturm 2017/03/13 21:12:46 Done.
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 previews can be shown for |type|.
24 bool IsPreviewsTypeEnabled(previews::PreviewsType type) {
25 switch (type) {
26 case previews::PreviewsType::OFFLINE:
27 return previews::params::IsOfflinePreviewsEnabled();
28 case previews::PreviewsType::NONE:
29 case previews::PreviewsType::LAST:
30 break;
31 }
32 NOTREACHED();
33 return false;
34 }
35
36 // Returns the version of preview treatment |type|. Defaults to 0 if not
37 // specified in field trial config.
38 int GetPreviewsTypeVersion(previews::PreviewsType type) {
39 switch (type) {
40 case previews::PreviewsType::OFFLINE:
41 return previews::params::OfflinePreviewsVersion();
42 case previews::PreviewsType::NONE:
43 case previews::PreviewsType::LAST:
44 break;
45 }
46 NOTREACHED();
47 return -1;
48 }
49
50 // Returns the enabled PreviewsTypes with their version.
51 std::unique_ptr<previews::PreviewsTypeList> GetEnabledPreviews() {
52 std::unique_ptr<previews::PreviewsTypeList> enabled_previews(
53 new previews::PreviewsTypeList());
54
55 // Loop across all previews types (relies on sequential enum values).
56 for (int i = static_cast<int>(previews::PreviewsType::NONE) + 1;
57 i < static_cast<int>(previews::PreviewsType::LAST); ++i) {
58 previews::PreviewsType type = static_cast<previews::PreviewsType>(i);
59 if (IsPreviewsTypeEnabled(type))
60 enabled_previews->push_back({type, GetPreviewsTypeVersion(type)});
61 }
62 return enabled_previews;
63 }
64
65 } // namespace
66
18 PreviewsService::PreviewsService() { 67 PreviewsService::PreviewsService() {
19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
20 } 69 }
21 70
22 PreviewsService::~PreviewsService() { 71 PreviewsService::~PreviewsService() {
23 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
24 } 73 }
25 74
26 void PreviewsService::Initialize( 75 void PreviewsService::Initialize(
27 previews::PreviewsIOData* previews_io_data, 76 previews::PreviewsIOData* previews_io_data,
28 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 77 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
29 const base::FilePath& profile_path) { 78 const base::FilePath& profile_path) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
31 80
32 base::SequencedWorkerPool* blocking_pool = 81 base::SequencedWorkerPool* blocking_pool =
33 content::BrowserThread::GetBlockingPool(); 82 content::BrowserThread::GetBlockingPool();
34 // Get the background thread to run SQLite on. 83 // Get the background thread to run SQLite on.
35 scoped_refptr<base::SequencedTaskRunner> background_task_runner = 84 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
36 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken()); 85 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken());
37 86
38 previews_ui_service_ = base::MakeUnique<previews::PreviewsUIService>( 87 previews_ui_service_ = base::MakeUnique<previews::PreviewsUIService>(
39 previews_io_data, io_task_runner, 88 previews_io_data, io_task_runner,
40 base::MakeUnique<previews::PreviewsOptOutStoreSQL>( 89 base::MakeUnique<previews::PreviewsOptOutStoreSQL>(
41 io_task_runner, background_task_runner, 90 io_task_runner, background_task_runner,
42 profile_path.Append(chrome::kPreviewsOptOutDBFilename))); 91 profile_path.Append(chrome::kPreviewsOptOutDBFilename),
92 GetEnabledPreviews()),
93 base::Bind(&IsPreviewsTypeEnabled));
43 } 94 }
OLDNEW
« no previous file with comments | « no previous file | components/previews/core/previews_experiments.h » ('j') | components/previews/core/previews_io_data_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698