| Index: chrome/browser/apps/drive/drive_app_mapping.cc
|
| diff --git a/chrome/browser/apps/drive/drive_app_mapping.cc b/chrome/browser/apps/drive/drive_app_mapping.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..83a4bf1976e640b14ed6bd8daf88d48a207fb3f4
|
| --- /dev/null
|
| +++ b/chrome/browser/apps/drive/drive_app_mapping.cc
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/apps/drive/drive_app_mapping.h"
|
| +
|
| +#include "base/prefs/pref_service.h"
|
| +#include "base/prefs/scoped_user_pref_update.h"
|
| +#include "base/values.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "components/pref_registry/pref_registry_syncable.h"
|
| +
|
| +DriveAppMapping::DriveAppMapping(PrefService* prefs) : prefs_(prefs) {
|
| +}
|
| +
|
| +DriveAppMapping::~DriveAppMapping() {
|
| +}
|
| +
|
| +// static
|
| +void DriveAppMapping::RegisterProfilePrefs(
|
| + user_prefs::PrefRegistrySyncable* registry) {
|
| + registry->RegisterDictionaryPref(
|
| + prefs::kAppLauncherDriveAppMapping,
|
| + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
|
| +}
|
| +
|
| +void DriveAppMapping::Add(const std::string& drive_app_id,
|
| + const std::string& chrome_app_id) {
|
| + DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping);
|
| + update->SetStringWithoutPathExpansion(drive_app_id, chrome_app_id);
|
| +}
|
| +
|
| +void DriveAppMapping::Remove(const std::string& drive_app_id) {
|
| + DictionaryPrefUpdate update(prefs_, prefs::kAppLauncherDriveAppMapping);
|
| + update->RemoveWithoutPathExpansion(drive_app_id, NULL);
|
| +}
|
| +
|
| +std::string DriveAppMapping::GetChromeApp(
|
| + const std::string& drive_app_id) const {
|
| + const base::DictionaryValue* mapping =
|
| + prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
|
| + std::string chrome_app_id;
|
| + if (mapping->GetStringWithoutPathExpansion(drive_app_id, &chrome_app_id))
|
| + return chrome_app_id;
|
| +
|
| + return std::string();
|
| +}
|
| +
|
| +std::string DriveAppMapping::GetDriveApp(
|
| + const std::string& chrome_app_id) const {
|
| + const base::DictionaryValue* mapping =
|
| + prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
|
| + for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd();
|
| + it.Advance()) {
|
| + std::string value_string;
|
| + DCHECK(it.value().IsType(base::Value::TYPE_STRING));
|
| + if (it.value().GetAsString(&value_string) &&
|
| + value_string == chrome_app_id) {
|
| + return it.key();
|
| + }
|
| + }
|
| + return std::string();
|
| +}
|
| +
|
| +std::set<std::string> DriveAppMapping::GetDriveAppIds() const {
|
| + const base::DictionaryValue* mapping =
|
| + prefs_->GetDictionary(prefs::kAppLauncherDriveAppMapping);
|
| + std::set<std::string> keys;
|
| + for (base::DictionaryValue::Iterator it(*mapping); !it.IsAtEnd();
|
| + it.Advance()) {
|
| + keys.insert(it.key());
|
| + }
|
| + return keys;
|
| +}
|
|
|