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 "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
16 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 15 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "components/user_manager/user.h" | 20 #include "components/user_manager/user.h" |
| 21 #include "components/user_manager/user_manager.h" |
22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
23 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
24 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
25 #include "net/url_request/url_fetcher_delegate.h" | 25 #include "net/url_request/url_fetcher_delegate.h" |
26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
27 | 27 |
28 using base::BinaryValue; | 28 using base::BinaryValue; |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 | 30 |
31 typedef base::Callback<void(bool success, const std::string&)> FetchCallback; | 31 typedef base::Callback<void(bool success, const std::string&)> FetchCallback; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { | 94 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { |
95 } | 95 } |
96 | 96 |
97 bool WallpaperSetWallpaperFunction::RunAsync() { | 97 bool WallpaperSetWallpaperFunction::RunAsync() { |
98 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
99 params_ = set_wallpaper::Params::Create(*args_); | 99 params_ = set_wallpaper::Params::Create(*args_); |
100 EXTENSION_FUNCTION_VALIDATE(params_); | 100 EXTENSION_FUNCTION_VALIDATE(params_); |
101 | 101 |
102 // Gets email address and username hash while at UI thread. | 102 // Gets email address and username hash while at UI thread. |
103 user_id_ = chromeos::UserManager::Get()->GetLoggedInUser()->email(); | 103 user_id_ = user_manager::UserManager::Get()->GetLoggedInUser()->email(); |
104 user_id_hash_ = | 104 user_id_hash_ = |
105 chromeos::UserManager::Get()->GetLoggedInUser()->username_hash(); | 105 user_manager::UserManager::Get()->GetLoggedInUser()->username_hash(); |
106 | 106 |
107 if (params_->details.wallpaper_data) { | 107 if (params_->details.wallpaper_data) { |
108 StartDecode(*params_->details.wallpaper_data); | 108 StartDecode(*params_->details.wallpaper_data); |
109 } else { | 109 } else { |
110 GURL wallpaper_url(*params_->details.url); | 110 GURL wallpaper_url(*params_->details.url); |
111 if (wallpaper_url.is_valid()) { | 111 if (wallpaper_url.is_valid()) { |
112 g_wallpaper_fetcher.Get().FetchWallpaper( | 112 g_wallpaper_fetcher.Get().FetchWallpaper( |
113 wallpaper_url, | 113 wallpaper_url, |
114 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); | 114 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); |
115 } else { | 115 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
131 | 131 |
132 sequence_token_ = BrowserThread::GetBlockingPool()-> | 132 sequence_token_ = BrowserThread::GetBlockingPool()-> |
133 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); | 133 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); |
134 scoped_refptr<base::SequencedTaskRunner> task_runner = | 134 scoped_refptr<base::SequencedTaskRunner> task_runner = |
135 BrowserThread::GetBlockingPool()-> | 135 BrowserThread::GetBlockingPool()-> |
136 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 136 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
137 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 137 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
138 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 138 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
139 set_wallpaper::Params::Details::ToString(params_->details.layout)); | 139 set_wallpaper::Params::Details::ToString(params_->details.layout)); |
140 bool update_wallpaper = | 140 bool update_wallpaper = |
141 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); | 141 user_id_ == user_manager::UserManager::Get()->GetActiveUser()->email(); |
142 wallpaper_manager->SetCustomWallpaper(user_id_, | 142 wallpaper_manager->SetCustomWallpaper(user_id_, |
143 user_id_hash_, | 143 user_id_hash_, |
144 params_->details.name, | 144 params_->details.name, |
145 layout, | 145 layout, |
146 user_manager::User::CUSTOMIZED, | 146 user_manager::User::CUSTOMIZED, |
147 image, | 147 image, |
148 update_wallpaper); | 148 update_wallpaper); |
149 unsafe_wallpaper_decoder_ = NULL; | 149 unsafe_wallpaper_decoder_ = NULL; |
150 | 150 |
151 if (params_->details.thumbnail) { | 151 if (params_->details.thumbnail) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 bool success, | 209 bool success, |
210 const std::string& response) { | 210 const std::string& response) { |
211 if (success) { | 211 if (success) { |
212 params_->details.wallpaper_data.reset(new std::string(response)); | 212 params_->details.wallpaper_data.reset(new std::string(response)); |
213 StartDecode(*params_->details.wallpaper_data); | 213 StartDecode(*params_->details.wallpaper_data); |
214 } else { | 214 } else { |
215 SetError(response); | 215 SetError(response); |
216 SendResponse(false); | 216 SendResponse(false); |
217 } | 217 } |
218 } | 218 } |
OLD | NEW |