Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/file_system_provider/registry.h" | 5 #include "chrome/browser/chromeos/file_system_provider/registry.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 namespace file_system_provider { | 24 namespace file_system_provider { |
| 25 | 25 |
| 26 const char kPrefKeyFileSystemId[] = "file-system-id"; | 26 const char kPrefKeyFileSystemId[] = "file-system-id"; |
| 27 const char kPrefKeyDisplayName[] = "display-name"; | 27 const char kPrefKeyDisplayName[] = "display-name"; |
| 28 const char kPrefKeyWritable[] = "writable"; | 28 const char kPrefKeyWritable[] = "writable"; |
| 29 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; | 29 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; |
| 30 const char kPrefKeyObservedEntries[] = "observed-entries"; | 30 const char kPrefKeyObservedEntries[] = "observed-entries"; |
| 31 const char kPrefKeyObservedEntryEntryPath[] = "entry-path"; | 31 const char kPrefKeyObservedEntryEntryPath[] = "entry-path"; |
| 32 const char kPrefKeyObservedEntryRecursive[] = "recursive"; | 32 const char kPrefKeyObservedEntryRecursive[] = "recursive"; |
| 33 const char kPrefKeyObservedEntryLastTag[] = "last-tag"; | 33 const char kPrefKeyObservedEntryLastTag[] = "last-tag"; |
| 34 const char kPrefKeyObservedEntryPersistentOrigins[] = "persistent-origins"; | |
| 34 | 35 |
| 35 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 36 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 36 registry->RegisterDictionaryPref( | 37 registry->RegisterDictionaryPref( |
| 37 prefs::kFileSystemProviderMounted, | 38 prefs::kFileSystemProviderMounted, |
| 38 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 39 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 39 } | 40 } |
| 40 | 41 |
| 41 Registry::Registry(Profile* profile) : profile_(profile) { | 42 Registry::Registry(Profile* profile) : profile_(profile) { |
| 42 } | 43 } |
| 43 | 44 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 65 for (const auto& it : observed_entries) { | 66 for (const auto& it : observed_entries) { |
| 66 base::DictionaryValue* const observed_entry = new base::DictionaryValue(); | 67 base::DictionaryValue* const observed_entry = new base::DictionaryValue(); |
| 67 observed_entries_value->SetWithoutPathExpansion( | 68 observed_entries_value->SetWithoutPathExpansion( |
| 68 it.second.entry_path.value(), observed_entry); | 69 it.second.entry_path.value(), observed_entry); |
| 69 observed_entry->SetStringWithoutPathExpansion( | 70 observed_entry->SetStringWithoutPathExpansion( |
| 70 kPrefKeyObservedEntryEntryPath, it.second.entry_path.value()); | 71 kPrefKeyObservedEntryEntryPath, it.second.entry_path.value()); |
| 71 observed_entry->SetBooleanWithoutPathExpansion( | 72 observed_entry->SetBooleanWithoutPathExpansion( |
| 72 kPrefKeyObservedEntryRecursive, it.second.recursive); | 73 kPrefKeyObservedEntryRecursive, it.second.recursive); |
| 73 observed_entry->SetStringWithoutPathExpansion(kPrefKeyObservedEntryLastTag, | 74 observed_entry->SetStringWithoutPathExpansion(kPrefKeyObservedEntryLastTag, |
| 74 it.second.last_tag); | 75 it.second.last_tag); |
| 76 base::ListValue* const persistent_origins_value = new base::ListValue(); | |
| 77 observed_entry->SetWithoutPathExpansion( | |
| 78 kPrefKeyObservedEntryPersistentOrigins, persistent_origins_value); | |
| 79 for (const auto& subscriber_it : it.second.subscribers) { | |
| 80 // Only persistent subscribers should be stored in persistent storage. | |
| 81 // Other ones should not be restired after a restart. | |
| 82 if (subscriber_it.second.persistent) | |
| 83 persistent_origins_value->AppendString(subscriber_it.first.spec()); | |
| 84 } | |
| 75 } | 85 } |
| 76 | 86 |
| 77 PrefService* const pref_service = profile_->GetPrefs(); | 87 PrefService* const pref_service = profile_->GetPrefs(); |
| 78 DCHECK(pref_service); | 88 DCHECK(pref_service); |
| 79 | 89 |
| 80 DictionaryPrefUpdate dict_update(pref_service, | 90 DictionaryPrefUpdate dict_update(pref_service, |
| 81 prefs::kFileSystemProviderMounted); | 91 prefs::kFileSystemProviderMounted); |
| 82 | 92 |
| 83 base::DictionaryValue* file_systems_per_extension = NULL; | 93 base::DictionaryValue* file_systems_per_extension = NULL; |
| 84 if (!dict_update->GetDictionaryWithoutPathExpansion( | 94 if (!dict_update->GetDictionaryWithoutPathExpansion( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 it.Advance()) { | 185 it.Advance()) { |
| 176 const base::Value* observed_entry_value = NULL; | 186 const base::Value* observed_entry_value = NULL; |
| 177 const base::DictionaryValue* observed_entry = NULL; | 187 const base::DictionaryValue* observed_entry = NULL; |
| 178 observed_entries->GetWithoutPathExpansion(it.key(), | 188 observed_entries->GetWithoutPathExpansion(it.key(), |
| 179 &observed_entry_value); | 189 &observed_entry_value); |
| 180 DCHECK(file_system_value); | 190 DCHECK(file_system_value); |
| 181 | 191 |
| 182 std::string entry_path; | 192 std::string entry_path; |
| 183 bool recursive = false; | 193 bool recursive = false; |
| 184 std::string last_tag; | 194 std::string last_tag; |
| 195 const base::ListValue* persistent_origins = NULL; | |
| 185 | 196 |
| 186 if (!observed_entry_value->GetAsDictionary(&observed_entry) || | 197 if (!observed_entry_value->GetAsDictionary(&observed_entry) || |
| 187 !observed_entry->GetStringWithoutPathExpansion( | 198 !observed_entry->GetStringWithoutPathExpansion( |
| 188 kPrefKeyObservedEntryEntryPath, &entry_path) || | 199 kPrefKeyObservedEntryEntryPath, &entry_path) || |
| 189 !observed_entry->GetBooleanWithoutPathExpansion( | 200 !observed_entry->GetBooleanWithoutPathExpansion( |
| 190 kPrefKeyObservedEntryRecursive, &recursive) || | 201 kPrefKeyObservedEntryRecursive, &recursive) || |
| 191 !observed_entry->GetStringWithoutPathExpansion( | 202 !observed_entry->GetStringWithoutPathExpansion( |
| 192 kPrefKeyObservedEntryLastTag, &last_tag) || | 203 kPrefKeyObservedEntryLastTag, &last_tag) || |
| 204 !observed_entry->GetListWithoutPathExpansion( | |
| 205 kPrefKeyObservedEntryPersistentOrigins, &persistent_origins) || | |
| 193 it.key() != entry_path || entry_path.empty() || | 206 it.key() != entry_path || entry_path.empty() || |
| 194 (!options.supports_notify_tag && !last_tag.empty())) { | 207 (!options.supports_notify_tag && |
| 208 (!last_tag.empty() || persistent_origins->GetSize()))) { | |
| 195 LOG(ERROR) << "Malformed observed entry information in preferences."; | 209 LOG(ERROR) << "Malformed observed entry information in preferences."; |
| 196 continue; | 210 continue; |
| 197 } | 211 } |
| 198 | 212 |
| 199 ObservedEntry restored_observed_entry; | 213 ObservedEntry restored_observed_entry; |
| 200 restored_observed_entry.entry_path = | 214 restored_observed_entry.entry_path = |
| 201 base::FilePath::FromUTF8Unsafe(entry_path); | 215 base::FilePath::FromUTF8Unsafe(entry_path); |
| 202 restored_observed_entry.recursive = recursive; | 216 restored_observed_entry.recursive = recursive; |
| 203 restored_observed_entry.last_tag = last_tag; | 217 restored_observed_entry.last_tag = last_tag; |
| 218 for (base::ListValue::const_iterator persistent_origin_it = | |
|
hirono
2014/10/27 08:15:15
nit: for (const auto& it : persistent_origins) for
mtomasz
2014/10/28 06:09:18
Done.
| |
| 219 persistent_origins->begin(); | |
| 220 persistent_origin_it != persistent_origins->end(); | |
| 221 ++persistent_origin_it) { | |
| 222 std::string origin; | |
| 223 if (!(*persistent_origin_it)->GetAsString(&origin)) { | |
| 224 LOG(ERROR) << "Malformed subscriber information in preferences."; | |
| 225 continue; | |
| 226 } | |
| 227 const GURL origin_as_gurl(origin); | |
| 228 restored_observed_entry.subscribers[origin_as_gurl].origin = | |
| 229 origin_as_gurl; | |
| 230 restored_observed_entry.subscribers[origin_as_gurl].persistent = true; | |
| 231 } | |
| 204 restored_file_system.observed_entries[ObservedEntryKey( | 232 restored_file_system.observed_entries[ObservedEntryKey( |
| 205 base::FilePath::FromUTF8Unsafe(entry_path), recursive)] = | 233 base::FilePath::FromUTF8Unsafe(entry_path), recursive)] = |
| 206 restored_observed_entry; | 234 restored_observed_entry; |
| 207 } | 235 } |
| 208 } | 236 } |
| 209 restored_file_systems->push_back(restored_file_system); | 237 restored_file_systems->push_back(restored_file_system); |
| 210 } | 238 } |
| 211 | 239 |
| 212 return restored_file_systems.Pass(); | 240 return restored_file_systems.Pass(); |
| 213 } | 241 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 241 LOG(ERROR) << "Broken preferences detected while updating a tag."; | 269 LOG(ERROR) << "Broken preferences detected while updating a tag."; |
| 242 return; | 270 return; |
| 243 } | 271 } |
| 244 | 272 |
| 245 observed_entry_value->SetStringWithoutPathExpansion( | 273 observed_entry_value->SetStringWithoutPathExpansion( |
| 246 kPrefKeyObservedEntryLastTag, observed_entry.last_tag); | 274 kPrefKeyObservedEntryLastTag, observed_entry.last_tag); |
| 247 } | 275 } |
| 248 | 276 |
| 249 } // namespace file_system_provider | 277 } // namespace file_system_provider |
| 250 } // namespace chromeos | 278 } // namespace chromeos |
| OLD | NEW |