Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / wallpaper_api.cc
index 7ce929d..e994f2d 100644 (file)
@@ -8,13 +8,17 @@
 #include "base/file_util.h"
 #include "base/lazy_instance.h"
 #include "base/path_service.h"
+#include "base/prefs/pref_service.h"
 #include "base/strings/stringprintf.h"
 #include "base/threading/worker_pool.h"
 #include "chrome/browser/browser_process.h"
-#include "chrome/browser/chromeos/login/user.h"
-#include "chrome/browser/chromeos/login/user_manager.h"
-#include "chrome/browser/chromeos/login/wallpaper_manager.h"
+#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
+#include "chrome/browser/profiles/profile.h"
 #include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/pref_names.h"
+#include "components/user_manager/user.h"
+#include "components/user_manager/user_manager.h"
 #include "net/base/load_flags.h"
 #include "net/http/http_status_code.h"
 #include "net/url_request/url_fetcher.h"
@@ -70,10 +74,7 @@ class WallpaperFetcher : public net::URLFetcherDelegate {
 
   void CancelPreviousFetch() {
     if (url_fetcher_.get()) {
-      std::string error = base::StringPrintf(
-          "Downloading wallpaper %s is canceled.",
-          url_fetcher_->GetOriginalURL().ExtractFileName().c_str());
-      callback_.Run(false, error);
+      callback_.Run(false, wallpaper_api_util::kCancelWallpaperMessage);
       url_fetcher_.reset();
     }
   }
@@ -94,13 +95,14 @@ WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() {
 }
 
 bool WallpaperSetWallpaperFunction::RunAsync() {
+  DCHECK_CURRENTLY_ON(BrowserThread::UI);
   params_ = set_wallpaper::Params::Create(*args_);
   EXTENSION_FUNCTION_VALIDATE(params_);
 
   // Gets email address and username hash while at UI thread.
-  user_id_ = chromeos::UserManager::Get()->GetLoggedInUser()->email();
+  user_id_ = user_manager::UserManager::Get()->GetLoggedInUser()->email();
   user_id_hash_ =
-      chromeos::UserManager::Get()->GetLoggedInUser()->username_hash();
+      user_manager::UserManager::Get()->GetLoggedInUser()->username_hash();
 
   if (params_->details.wallpaper_data) {
     StartDecode(*params_->details.wallpaper_data);
@@ -136,12 +138,12 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
   ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
       set_wallpaper::Params::Details::ToString(params_->details.layout));
   bool update_wallpaper =
-      user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email();
+      user_id_ == user_manager::UserManager::Get()->GetActiveUser()->email();
   wallpaper_manager->SetCustomWallpaper(user_id_,
                                         user_id_hash_,
                                         params_->details.name,
                                         layout,
-                                        chromeos::User::CUSTOMIZED,
+                                        user_manager::User::CUSTOMIZED,
                                         image,
                                         update_wallpaper);
   unsafe_wallpaper_decoder_ = NULL;
@@ -158,6 +160,17 @@ void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
                    thumbnail_path,
                    base::Passed(deep_copy.Pass())));
   } else {
+    // Save current extenion name. It will be displayed in the component
+    // wallpaper picker app. If current extension is the component wallpaper
+    // picker, set an empty string.
+    Profile* profile = Profile::FromBrowserContext(browser_context());
+    if (extension()->id() == extension_misc::kWallpaperManagerId) {
+      profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
+                                     std::string());
+    } else {
+      profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
+                                     extension()->name());
+    }
     SendResponse(true);
   }
 }