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 <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
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/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
| 17 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 19 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
19 #include "chrome/browser/chromeos/file_manager/app_id.h" | 20 #include "chrome/browser/chromeos/file_manager/app_id.h" |
20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 21 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
27 #include "components/user_manager/user.h" | 28 #include "components/user_manager/user.h" |
28 #include "components/user_manager/user_manager.h" | 29 #include "components/user_manager/user_manager.h" |
29 #include "components/wallpaper/wallpaper_layout.h" | 30 #include "components/wallpaper/wallpaper_layout.h" |
30 #include "extensions/browser/event_router.h" | 31 #include "extensions/browser/event_router.h" |
31 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
32 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
33 #include "net/url_request/url_fetcher.h" | 34 #include "net/url_request/url_fetcher.h" |
34 #include "net/url_request/url_fetcher_delegate.h" | 35 #include "net/url_request/url_fetcher_delegate.h" |
35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
36 | 37 |
37 using base::BinaryValue; | 38 using base::Value; |
38 using content::BrowserThread; | 39 using content::BrowserThread; |
39 | 40 |
40 typedef base::Callback<void(bool success, const std::string&)> FetchCallback; | 41 typedef base::Callback<void(bool success, const std::string&)> FetchCallback; |
41 | 42 |
42 namespace set_wallpaper = extensions::api::wallpaper::SetWallpaper; | 43 namespace set_wallpaper = extensions::api::wallpaper::SetWallpaper; |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 class WallpaperFetcher : public net::URLFetcherDelegate { | 47 class WallpaperFetcher : public net::URLFetcherDelegate { |
47 public: | 48 public: |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 BrowserThread::PostTask( | 221 BrowserThread::PostTask( |
221 BrowserThread::UI, FROM_HERE, | 222 BrowserThread::UI, FROM_HERE, |
222 base::Bind(&WallpaperSetWallpaperFunction::ThumbnailGenerated, this, | 223 base::Bind(&WallpaperSetWallpaperFunction::ThumbnailGenerated, this, |
223 base::RetainedRef(original_data), | 224 base::RetainedRef(original_data), |
224 base::RetainedRef(thumbnail_data))); | 225 base::RetainedRef(thumbnail_data))); |
225 } | 226 } |
226 | 227 |
227 void WallpaperSetWallpaperFunction::ThumbnailGenerated( | 228 void WallpaperSetWallpaperFunction::ThumbnailGenerated( |
228 base::RefCountedBytes* original_data, | 229 base::RefCountedBytes* original_data, |
229 base::RefCountedBytes* thumbnail_data) { | 230 base::RefCountedBytes* thumbnail_data) { |
230 std::unique_ptr<BinaryValue> original_result = | 231 std::unique_ptr<Value> original_result = Value::CreateWithCopiedBuffer( |
231 BinaryValue::CreateWithCopiedBuffer( | 232 reinterpret_cast<const char*>(original_data->front()), |
232 reinterpret_cast<const char*>(original_data->front()), | 233 original_data->size()); |
233 original_data->size()); | 234 std::unique_ptr<Value> thumbnail_result = Value::CreateWithCopiedBuffer( |
234 std::unique_ptr<BinaryValue> thumbnail_result = | 235 reinterpret_cast<const char*>(thumbnail_data->front()), |
235 BinaryValue::CreateWithCopiedBuffer( | 236 thumbnail_data->size()); |
236 reinterpret_cast<const char*>(thumbnail_data->front()), | |
237 thumbnail_data->size()); | |
238 | 237 |
239 if (params_->details.thumbnail) { | 238 if (params_->details.thumbnail) { |
240 SetResult(thumbnail_result->CreateDeepCopy()); | 239 SetResult(thumbnail_result->CreateDeepCopy()); |
241 SendResponse(true); | 240 SendResponse(true); |
242 } | 241 } |
243 | 242 |
244 // Inform the native Wallpaper Picker Application that the current wallpaper | 243 // Inform the native Wallpaper Picker Application that the current wallpaper |
245 // has been modified by a third party application. | 244 // has been modified by a third party application. |
246 if (extension()->id() != extension_misc::kWallpaperManagerId) { | 245 if (extension()->id() != extension_misc::kWallpaperManagerId) { |
247 Profile* profile = Profile::FromBrowserContext(browser_context()); | 246 Profile* profile = Profile::FromBrowserContext(browser_context()); |
(...skipping 30 matching lines...) Expand all Loading... |
278 const std::string& response) { | 277 const std::string& response) { |
279 if (success) { | 278 if (success) { |
280 params_->details.data.reset( | 279 params_->details.data.reset( |
281 new std::vector<char>(response.begin(), response.end())); | 280 new std::vector<char>(response.begin(), response.end())); |
282 StartDecode(*params_->details.data); | 281 StartDecode(*params_->details.data); |
283 } else { | 282 } else { |
284 SetError(response); | 283 SetError(response); |
285 SendResponse(false); | 284 SendResponse(false); |
286 } | 285 } |
287 } | 286 } |
OLD | NEW |