Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 namespace get_offline_wallpaper_list = | 61 namespace get_offline_wallpaper_list = |
| 62 wallpaper_private::GetOfflineWallpaperList; | 62 wallpaper_private::GetOfflineWallpaperList; |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 #if defined(GOOGLE_CHROME_BUILD) | 66 #if defined(GOOGLE_CHROME_BUILD) |
| 67 const char kWallpaperManifestBaseURL[] = | 67 const char kWallpaperManifestBaseURL[] = |
| 68 "https://storage.googleapis.com/chromeos-wallpaper-public/manifest_"; | 68 "https://storage.googleapis.com/chromeos-wallpaper-public/manifest_"; |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 // Keep this value the same with the corresponding constant defined in | |
| 72 // chrome/browser/resources/chromeos/wallpaper_manager/js/constants.js. | |
| 73 const char kThirdPartyWallpaperPrefix[] = "third_party_"; | |
| 74 | |
| 71 bool IsOEMDefaultWallpaper() { | 75 bool IsOEMDefaultWallpaper() { |
| 72 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 76 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 73 chromeos::switches::kDefaultWallpaperIsOem); | 77 chromeos::switches::kDefaultWallpaperIsOem); |
| 74 } | 78 } |
| 75 | 79 |
| 76 // Saves |data| as |file_name| to directory with |key|. Return false if the | 80 // Saves |data| as |file_name| to directory with |key|. Return false if the |
| 77 // directory can not be found/created or failed to write file. | 81 // directory can not be found/created or failed to write file. |
| 78 bool SaveData(int key, | 82 bool SaveData(int key, |
| 79 const std::string& file_name, | 83 const std::string& file_name, |
| 80 const std::vector<char>& data) { | 84 const std::vector<char>& data) { |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 | 631 |
| 628 bool update_wallpaper = | 632 bool update_wallpaper = |
| 629 account_id_ == | 633 account_id_ == |
| 630 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | 634 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
| 631 wallpaper_manager->SetCustomWallpaper( | 635 wallpaper_manager->SetCustomWallpaper( |
| 632 account_id_, user_id_hash_, params->file_name, layout, | 636 account_id_, user_id_hash_, params->file_name, layout, |
| 633 user_manager::User::CUSTOMIZED, image, update_wallpaper); | 637 user_manager::User::CUSTOMIZED, image, update_wallpaper); |
| 634 unsafe_wallpaper_decoder_ = NULL; | 638 unsafe_wallpaper_decoder_ = NULL; |
| 635 | 639 |
| 636 Profile* profile = Profile::FromBrowserContext(browser_context()); | 640 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 637 // This API is only available to the component wallpaper picker. We do not | 641 // This API is only available to the component wallpaper picker. It can be |
| 638 // need to show the app's name if it is the component wallpaper picker. So set | 642 // called to set a custom wallpaper or sync a third party wallpaper. We need |
| 639 // the pref to empty string. | 643 // to set the pref according to different types of wallpapers. |
|
tbarzic
2016/01/26 01:20:44
I assume this prefs should be set by third-party a
xdai1
2016/01/26 17:57:48
Currently the 3rd party wallpaper syncing scenario
tbarzic
2016/01/26 18:57:26
Yep, I assumed as much. What I'd like is for the c
| |
| 640 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 644 if (params->file_name.find(kThirdPartyWallpaperPrefix) == std::string::npos) { |
|
tbarzic
2016/01/26 01:20:44
Can this logic be moved to wallpaper app?
E.g. add
xdai1
2016/01/26 17:57:48
Yes, it can be moved to wallpaper app by introduci
tbarzic
2016/01/26 18:57:26
Yes, but I would prefer not to leak file name form
| |
| 641 std::string()); | 645 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 646 std::string()); | |
| 647 } | |
| 642 | 648 |
| 643 if (params->generate_thumbnail) { | 649 if (params->generate_thumbnail) { |
| 644 image.EnsureRepsForSupportedScales(); | 650 image.EnsureRepsForSupportedScales(); |
| 645 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 651 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
| 646 // Generates thumbnail before call api function callback. We can then | 652 // Generates thumbnail before call api function callback. We can then |
| 647 // request thumbnail in the javascript callback. | 653 // request thumbnail in the javascript callback. |
| 648 task_runner->PostTask(FROM_HERE, | 654 task_runner->PostTask(FROM_HERE, |
| 649 base::Bind( | 655 base::Bind( |
| 650 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, | 656 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, |
| 651 this, thumbnail_path, base::Passed(&deep_copy))); | 657 this, thumbnail_path, base::Passed(&deep_copy))); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 this, file_list)); | 933 this, file_list)); |
| 928 } | 934 } |
| 929 | 935 |
| 930 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 936 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
| 931 const std::vector<std::string>& file_list) { | 937 const std::vector<std::string>& file_list) { |
| 932 base::ListValue* results = new base::ListValue(); | 938 base::ListValue* results = new base::ListValue(); |
| 933 results->AppendStrings(file_list); | 939 results->AppendStrings(file_list); |
| 934 SetResult(results); | 940 SetResult(results); |
| 935 SendResponse(true); | 941 SendResponse(true); |
| 936 } | 942 } |
| OLD | NEW |