OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/apps/drive/drive_app_mapping.h" |
| 6 |
| 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/prefs/scoped_user_pref_update.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/pref_registry/pref_registry_syncable.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 DriveAppMapping::DriveAppMapping(PrefService* prefs) : prefs_(prefs) { |
| 16 } |
| 17 |
| 18 DriveAppMapping::~DriveAppMapping() { |
| 19 } |
| 20 |
| 21 // static |
| 22 void DriveAppMapping::RegisterProfilePrefs( |
| 23 user_prefs::PrefRegistrySyncable* registry) { |
| 24 registry->RegisterDictionaryPref( |
| 25 prefs::kAppLauncherDriveAppMapping, |
| 26 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 27 } |
| 28 |
| 29 void DriveAppMapping::Add(const std::string& drive_app_id, |
| 30 const std::string& chrome_app_id) { |
| 31 DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping); |
| 32 update->SetStringWithoutPathExpansion(drive_app_id, chrome_app_id); |
| 33 } |
| 34 |
| 35 void DriveAppMapping::Remove(const std::string& drive_app_id) { |
| 36 DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping); |
| 37 update->RemoveWithoutPathExpansion(drive_app_id, NULL); |
| 38 } |
| 39 |
| 40 std::string DriveAppMapping::GetChromeApp( |
| 41 const std::string& drive_app_id) const { |
| 42 const base::DictionaryValue* mapping = |
| 43 prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping); |
| 44 std::string chrome_app_id; |
| 45 if (mapping->GetStringWithoutPathExpansion(drive_app_id, &chrome_app_id)) |
| 46 return chrome_app_id; |
| 47 |
| 48 return std::string(); |
| 49 } |
| 50 |
| 51 std::string DriveAppMapping::GetDriveApp( |
| 52 const std::string& chrome_app_id) const { |
| 53 const base::DictionaryValue* mapping = |
| 54 prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping); |
| 55 for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd(); |
| 56 it.Advance()) { |
| 57 std::string value_string; |
| 58 DCHECK(it.value().IsType(base::Value::TYPE_STRING)); |
| 59 if (it.value().GetAsString(&value_string) && |
| 60 value_string == chrome_app_id) { |
| 61 return it.key(); |
| 62 } |
| 63 } |
| 64 return std::string(); |
| 65 } |
| 66 |
| 67 std::set<std::string> DriveAppMapping::GetDriveAppIds() const { |
| 68 const base::DictionaryValue* mapping = |
| 69 prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping); |
| 70 std::set<std::string> keys; |
| 71 for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd(); |
| 72 it.Advance()) { |
| 73 keys.insert(it.key()); |
| 74 } |
| 75 return keys; |
| 76 } |
| 77 |
| 78 } // namespace extensions |
OLD | NEW |