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

Unified Diff: chrome/browser/previews/previews_service.cc

Issue 2739033005: Moving previews code from components/ to chrome/ (Closed)
Patch Set: tbansal comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/previews/core/previews_experiments.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/previews/previews_service.cc
diff --git a/chrome/browser/previews/previews_service.cc b/chrome/browser/previews/previews_service.cc
index bfc31eaa413f45c50099d837c54aab0ec5c4a08c..a0375e5f8833c32f8b2d615610ebdcf4e32b4689 100644
--- a/chrome/browser/previews/previews_service.cc
+++ b/chrome/browser/previews/previews_service.cc
@@ -4,17 +4,65 @@
#include "chrome/browser/previews/previews_service.h"
+#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/memory/ptr_util.h"
#include "base/sequenced_task_runner.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/common/chrome_constants.h"
+#include "components/previews/core/previews_experiments.h"
#include "components/previews/core/previews_io_data.h"
#include "components/previews/core/previews_opt_out_store.h"
#include "components/previews/core/previews_opt_out_store_sql.h"
#include "components/previews/core/previews_ui_service.h"
#include "content/public/browser/browser_thread.h"
+namespace {
+
+// Returns true if previews can be shown for |type|.
+bool IsPreviewsTypeEnabled(previews::PreviewsType type) {
+ switch (type) {
+ case previews::PreviewsType::OFFLINE:
+ return previews::params::IsOfflinePreviewsEnabled();
+ case previews::PreviewsType::NONE:
+ case previews::PreviewsType::LAST:
+ break;
+ }
+ NOTREACHED();
+ return false;
+}
+
+// Returns the version of preview treatment |type|. Defaults to 0 if not
+// specified in field trial config.
+int GetPreviewsTypeVersion(previews::PreviewsType type) {
+ switch (type) {
+ case previews::PreviewsType::OFFLINE:
+ return previews::params::OfflinePreviewsVersion();
+ case previews::PreviewsType::NONE:
+ case previews::PreviewsType::LAST:
+ break;
+ }
+ NOTREACHED();
+ return -1;
+}
+
+// Returns the enabled PreviewsTypes with their version.
+std::unique_ptr<previews::PreviewsTypeList> GetEnabledPreviews() {
+ std::unique_ptr<previews::PreviewsTypeList> enabled_previews(
+ new previews::PreviewsTypeList());
+
+ // Loop across all previews types (relies on sequential enum values).
+ for (int i = static_cast<int>(previews::PreviewsType::NONE) + 1;
+ i < static_cast<int>(previews::PreviewsType::LAST); ++i) {
+ previews::PreviewsType type = static_cast<previews::PreviewsType>(i);
+ if (IsPreviewsTypeEnabled(type))
+ enabled_previews->push_back({type, GetPreviewsTypeVersion(type)});
+ }
+ return enabled_previews;
+}
+
+} // namespace
+
PreviewsService::PreviewsService() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
@@ -39,5 +87,7 @@ void PreviewsService::Initialize(
previews_io_data, io_task_runner,
base::MakeUnique<previews::PreviewsOptOutStoreSQL>(
io_task_runner, background_task_runner,
- profile_path.Append(chrome::kPreviewsOptOutDBFilename)));
+ profile_path.Append(chrome::kPreviewsOptOutDBFilename),
+ GetEnabledPreviews()),
+ base::Bind(&IsPreviewsTypeEnabled));
}
« no previous file with comments | « no previous file | components/previews/core/previews_experiments.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698