Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/wallpaper_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "components/user_manager/user.h" | 22 #include "components/user_manager/user.h" |
| 23 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.h" |
| 24 #include "components/wallpaper/wallpaper_layout.h" | 24 #include "components/wallpaper/wallpaper_layout.h" |
| 25 #include "extensions/browser/event_router.h" | |
| 25 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| 26 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
| 27 #include "net/url_request/url_fetcher.h" | 28 #include "net/url_request/url_fetcher.h" |
| 28 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 30 | 31 |
| 31 using base::BinaryValue; | 32 using base::BinaryValue; |
| 32 using content::BrowserThread; | 33 using content::BrowserThread; |
| 33 | 34 |
| 34 typedef base::Callback<void(bool success, const std::string&)> FetchCallback; | 35 typedef base::Callback<void(bool success, const std::string&)> FetchCallback; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 GURL wallpaper_url(*params_->details.url); | 114 GURL wallpaper_url(*params_->details.url); |
| 114 if (wallpaper_url.is_valid()) { | 115 if (wallpaper_url.is_valid()) { |
| 115 g_wallpaper_fetcher.Get().FetchWallpaper( | 116 g_wallpaper_fetcher.Get().FetchWallpaper( |
| 116 wallpaper_url, | 117 wallpaper_url, |
| 117 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); | 118 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); |
| 118 } else { | 119 } else { |
| 119 SetError("URL is invalid."); | 120 SetError("URL is invalid."); |
| 120 SendResponse(false); | 121 SendResponse(false); |
| 121 } | 122 } |
| 122 } | 123 } |
| 124 | |
| 125 Profile* profile = Profile::FromBrowserContext(browser_context()); | |
| 126 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); | |
| 127 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | |
| 128 scoped_ptr<extensions::Event> event(new extensions::Event( | |
| 129 extensions::api::wallpaper::OnWallpaperChangedBy3rdParty::kEventName, | |
| 130 event_args.Pass())); | |
| 131 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, | |
| 132 event.Pass()); | |
|
bshe
2015/03/16 14:02:40
We should send the event only after we know for su
| |
| 123 return true; | 133 return true; |
| 124 } | 134 } |
| 125 | 135 |
| 126 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( | 136 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( |
| 127 const gfx::ImageSkia& image) { | 137 const gfx::ImageSkia& image) { |
| 128 chromeos::WallpaperManager* wallpaper_manager = | 138 chromeos::WallpaperManager* wallpaper_manager = |
| 129 chromeos::WallpaperManager::Get(); | 139 chromeos::WallpaperManager::Get(); |
| 130 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( | 140 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( |
| 131 wallpaper::kThumbnailWallpaperSubDir, user_id_hash_, | 141 wallpaper::kThumbnailWallpaperSubDir, user_id_hash_, |
| 132 params_->details.filename); | 142 params_->details.filename); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 const std::string& response) { | 219 const std::string& response) { |
| 210 if (success) { | 220 if (success) { |
| 211 params_->details.data.reset( | 221 params_->details.data.reset( |
| 212 new std::vector<char>(response.begin(), response.end())); | 222 new std::vector<char>(response.begin(), response.end())); |
| 213 StartDecode(*params_->details.data); | 223 StartDecode(*params_->details.data); |
| 214 } else { | 224 } else { |
| 215 SetError(response); | 225 SetError(response); |
| 216 SendResponse(false); | 226 SendResponse(false); |
| 217 } | 227 } |
| 218 } | 228 } |
| OLD | NEW |