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 DriveAppMapping::DriveAppMapping(PrefService* prefs) : prefs_(prefs) { |
| 14 } |
| 15 |
| 16 DriveAppMapping::~DriveAppMapping() { |
| 17 } |
| 18 |
| 19 // static |
| 20 void DriveAppMapping::RegisterProfilePrefs( |
| 21 user_prefs::PrefRegistrySyncable* registry) { |
| 22 registry->RegisterDictionaryPref( |
| 23 prefs::kAppLauncherDriveAppMapping, |
| 24 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 25 } |
| 26 |
| 27 void DriveAppMapping::Add(const std::string& drive_app_id, |
| 28 const std::string& chrome_app_id) { |
| 29 DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping); |
| 30 update->SetStringWithoutPathExpansion(drive_app_id, chrome_app_id); |
| 31 } |
| 32 |
| 33 void DriveAppMapping::Remove(const std::string& drive_app_id) { |
| 34 DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping); |
| 35 update->RemoveWithoutPathExpansion(drive_app_id, NULL); |
| 36 } |
| 37 |
| 38 std::string DriveAppMapping::GetChromeApp( |
| 39 const std::string& drive_app_id) const { |
| 40 const base::DictionaryValue* mapping = |
| 41 prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping); |
| 42 std::string chrome_app_id; |
| 43 if (mapping->GetStringWithoutPathExpansion(drive_app_id, &chrome_app_id)) |
| 44 return chrome_app_id; |
| 45 |
| 46 return std::string(); |
| 47 } |
| 48 |
| 49 std::string DriveAppMapping::GetDriveApp( |
| 50 const std::string& chrome_app_id) const { |
| 51 const base::DictionaryValue* mapping = |
| 52 prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping); |
| 53 for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd(); |
| 54 it.Advance()) { |
| 55 std::string value_string; |
| 56 DCHECK(it.value().IsType(base::Value::TYPE_STRING)); |
| 57 if (it.value().GetAsString(&value_string) && |
| 58 value_string == chrome_app_id) { |
| 59 return it.key(); |
| 60 } |
| 61 } |
| 62 return std::string(); |
| 63 } |
| 64 |
| 65 std::set<std::string> DriveAppMapping::GetDriveAppIds() const { |
| 66 const base::DictionaryValue* mapping = |
| 67 prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping); |
| 68 std::set<std::string> keys; |
| 69 for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd(); |
| 70 it.Advance()) { |
| 71 keys.insert(it.key()); |
| 72 } |
| 73 return keys; |
| 74 } |
OLD | NEW |