Commit 4be75bac authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Fix nits in Wallpaper extension API code.

Change-Id: Iff32093fe4339338c3e5bb025049034f90dd6e53
Reviewed-on: https://chromium-review.googlesource.com/1215043Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590051}
parent 1094a6a2
...@@ -4,12 +4,8 @@ ...@@ -4,12 +4,8 @@
#include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
#include <map> #include <algorithm>
#include <memory>
#include <set>
#include <string>
#include <utility> #include <utility>
#include <vector>
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -70,12 +66,14 @@ namespace get_surprise_me_image = wallpaper_private::GetSurpriseMeImage; ...@@ -70,12 +66,14 @@ namespace get_surprise_me_image = wallpaper_private::GetSurpriseMeImage;
namespace { namespace {
// The time in seconds and retry limit to re-check the profile sync service // The time and retry limit to re-check the profile sync service status. The
// status. Only after the profile sync service has been configured, we can get // sync extension function can get the correct value of the "syncThemes" user
// the correct value of the user sync preference of "syncThemes". // preference only after the profile sync service has been configured.
constexpr int kRetryDelay = 10; constexpr base::TimeDelta kRetryDelay = base::TimeDelta::FromSeconds(10);
constexpr int kRetryLimit = 3; constexpr int kRetryLimit = 3;
constexpr char kSyncThemes[] = "syncThemes";
constexpr char kPngFilePattern[] = "*.[pP][nN][gG]"; constexpr char kPngFilePattern[] = "*.[pP][nN][gG]";
constexpr char kJpgFilePattern[] = "*.[jJ][pP][gG]"; constexpr char kJpgFilePattern[] = "*.[jJ][pP][gG]";
constexpr char kJpegFilePattern[] = "*.[jJ][pP][eE][gG]"; constexpr char kJpegFilePattern[] = "*.[jJ][pP][eE][gG]";
...@@ -152,7 +150,7 @@ const user_manager::User* GetUserFromBrowserContext( ...@@ -152,7 +150,7 @@ const user_manager::User* GetUserFromBrowserContext(
return user; return user;
} }
ash::WallpaperType getWallpaperType(wallpaper_private::WallpaperSource source) { ash::WallpaperType GetWallpaperType(wallpaper_private::WallpaperSource source) {
switch (source) { switch (source) {
case wallpaper_private::WALLPAPER_SOURCE_ONLINE: case wallpaper_private::WALLPAPER_SOURCE_ONLINE:
return ash::ONLINE; return ash::ONLINE;
...@@ -295,11 +293,11 @@ WallpaperPrivateGetSyncSettingFunction::Run() { ...@@ -295,11 +293,11 @@ WallpaperPrivateGetSyncSettingFunction::Run() {
void WallpaperPrivateGetSyncSettingFunction::CheckProfileSyncServiceStatus() { void WallpaperPrivateGetSyncSettingFunction::CheckProfileSyncServiceStatus() {
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
if (retry_number > kRetryLimit) { if (retry_number_ > kRetryLimit) {
// It's most likely that the wallpaper synchronization is enabled (It's // It's most likely that the wallpaper synchronization is enabled (It's
// enabled by default so unless the user disables it explicitly it remains // enabled by default so unless the user disables it explicitly it remains
// enabled). // enabled).
dict->SetBoolean("syncThemes", true); dict->SetBoolean(kSyncThemes, true);
Respond(OneArgument(std::move(dict))); Respond(OneArgument(std::move(dict)));
return; return;
} }
...@@ -308,14 +306,14 @@ void WallpaperPrivateGetSyncSettingFunction::CheckProfileSyncServiceStatus() { ...@@ -308,14 +306,14 @@ void WallpaperPrivateGetSyncSettingFunction::CheckProfileSyncServiceStatus() {
browser_sync::ProfileSyncService* sync_service = browser_sync::ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
if (!sync_service) { if (!sync_service) {
dict->SetBoolean("syncThemes", false); dict->SetBoolean(kSyncThemes, false);
Respond(OneArgument(std::move(dict))); Respond(OneArgument(std::move(dict)));
return; return;
} }
if (sync_service->GetTransportState() == if (sync_service->GetTransportState() ==
syncer::SyncService::TransportState::ACTIVE) { syncer::SyncService::TransportState::ACTIVE) {
dict->SetBoolean("syncThemes", dict->SetBoolean(kSyncThemes,
sync_service->GetActiveDataTypes().Has(syncer::THEMES)); sync_service->GetActiveDataTypes().Has(syncer::THEMES));
Respond(OneArgument(std::move(dict))); Respond(OneArgument(std::move(dict)));
return; return;
...@@ -325,13 +323,13 @@ void WallpaperPrivateGetSyncSettingFunction::CheckProfileSyncServiceStatus() { ...@@ -325,13 +323,13 @@ void WallpaperPrivateGetSyncSettingFunction::CheckProfileSyncServiceStatus() {
// when we're trying to query the user preference (this seems only happen for // when we're trying to query the user preference (this seems only happen for
// the first time configuration). In this case GetActiveDataTypes() returns an // the first time configuration). In this case GetActiveDataTypes() returns an
// empty set. So re-check the status later. // empty set. So re-check the status later.
retry_number++; retry_number_++;
BrowserThread::PostDelayedTask( BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&WallpaperPrivateGetSyncSettingFunction:: base::BindOnce(&WallpaperPrivateGetSyncSettingFunction::
CheckProfileSyncServiceStatus, CheckProfileSyncServiceStatus,
this), this),
base::TimeDelta::FromSeconds(retry_number * kRetryDelay)); retry_number_ * kRetryDelay);
} }
WallpaperPrivateSetWallpaperIfExistsFunction:: WallpaperPrivateSetWallpaperIfExistsFunction::
...@@ -673,7 +671,7 @@ WallpaperPrivateRecordWallpaperUMAFunction::Run() { ...@@ -673,7 +671,7 @@ WallpaperPrivateRecordWallpaperUMAFunction::Run() {
record_wallpaper_uma::Params::Create(*args_)); record_wallpaper_uma::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
ash::WallpaperType source = getWallpaperType(params->source); ash::WallpaperType source = GetWallpaperType(params->source);
UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source, UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source,
ash::WALLPAPER_TYPE_COUNT); ash::WALLPAPER_TYPE_COUNT);
return RespondNow(NoArguments()); return RespondNow(NoArguments());
......
...@@ -58,7 +58,7 @@ class WallpaperPrivateGetSyncSettingFunction ...@@ -58,7 +58,7 @@ class WallpaperPrivateGetSyncSettingFunction
void CheckProfileSyncServiceStatus(); void CheckProfileSyncServiceStatus();
// The retry number to check to profile sync service status. // The retry number to check to profile sync service status.
int retry_number = 0; int retry_number_ = 0;
}; };
class WallpaperPrivateSetWallpaperIfExistsFunction class WallpaperPrivateSetWallpaperIfExistsFunction
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment