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 <utility> | |
8 | |
9 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
10 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
11 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
13 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 11 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
16 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
(...skipping 24 matching lines...) Expand all Loading... |
43 | 41 |
44 Registry::Registry(Profile* profile) : profile_(profile) { | 42 Registry::Registry(Profile* profile) : profile_(profile) { |
45 } | 43 } |
46 | 44 |
47 Registry::~Registry() { | 45 Registry::~Registry() { |
48 } | 46 } |
49 | 47 |
50 void Registry::RememberFileSystem( | 48 void Registry::RememberFileSystem( |
51 const ProvidedFileSystemInfo& file_system_info, | 49 const ProvidedFileSystemInfo& file_system_info, |
52 const Watchers& watchers) { | 50 const Watchers& watchers) { |
53 auto file_system = base::MakeUnique<base::DictionaryValue>(); | 51 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
54 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 52 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
55 file_system_info.file_system_id()); | 53 file_system_info.file_system_id()); |
56 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, | 54 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, |
57 file_system_info.display_name()); | 55 file_system_info.display_name()); |
58 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, | 56 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, |
59 file_system_info.writable()); | 57 file_system_info.writable()); |
60 file_system->SetBooleanWithoutPathExpansion( | 58 file_system->SetBooleanWithoutPathExpansion( |
61 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); | 59 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); |
62 file_system->SetIntegerWithoutPathExpansion( | 60 file_system->SetIntegerWithoutPathExpansion( |
63 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); | 61 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); |
64 | 62 |
65 auto watchers_value = base::MakeUnique<base::DictionaryValue>(); | 63 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); |
| 64 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); |
66 | 65 |
67 for (const auto& it : watchers) { | 66 for (const auto& it : watchers) { |
68 auto watcher = base::MakeUnique<base::DictionaryValue>(); | 67 base::DictionaryValue* const watcher = new base::DictionaryValue(); |
| 68 watchers_value->SetWithoutPathExpansion(it.second.entry_path.value(), |
| 69 watcher); |
69 watcher->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, | 70 watcher->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, |
70 it.second.entry_path.value()); | 71 it.second.entry_path.value()); |
71 watcher->SetBooleanWithoutPathExpansion(kPrefKeyWatcherRecursive, | 72 watcher->SetBooleanWithoutPathExpansion(kPrefKeyWatcherRecursive, |
72 it.second.recursive); | 73 it.second.recursive); |
73 watcher->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 74 watcher->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
74 it.second.last_tag); | 75 it.second.last_tag); |
75 auto persistent_origins_value = base::MakeUnique<base::ListValue>(); | 76 base::ListValue* const persistent_origins_value = new base::ListValue(); |
| 77 watcher->SetWithoutPathExpansion(kPrefKeyWatcherPersistentOrigins, |
| 78 persistent_origins_value); |
76 for (const auto& subscriber_it : it.second.subscribers) { | 79 for (const auto& subscriber_it : it.second.subscribers) { |
77 // Only persistent subscribers should be stored in persistent storage. | 80 // Only persistent subscribers should be stored in persistent storage. |
78 // Other ones should not be restired after a restart. | 81 // Other ones should not be restired after a restart. |
79 if (subscriber_it.second.persistent) | 82 if (subscriber_it.second.persistent) |
80 persistent_origins_value->AppendString(subscriber_it.first.spec()); | 83 persistent_origins_value->AppendString(subscriber_it.first.spec()); |
81 } | 84 } |
82 watcher->SetWithoutPathExpansion(kPrefKeyWatcherPersistentOrigins, | |
83 std::move(persistent_origins_value)); | |
84 watchers_value->SetWithoutPathExpansion(it.second.entry_path.value(), | |
85 std::move(watcher)); | |
86 } | 85 } |
87 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, | |
88 std::move(watchers_value)); | |
89 | 86 |
90 PrefService* const pref_service = profile_->GetPrefs(); | 87 PrefService* const pref_service = profile_->GetPrefs(); |
91 DCHECK(pref_service); | 88 DCHECK(pref_service); |
92 | 89 |
93 DictionaryPrefUpdate dict_update(pref_service, | 90 DictionaryPrefUpdate dict_update(pref_service, |
94 prefs::kFileSystemProviderMounted); | 91 prefs::kFileSystemProviderMounted); |
95 | 92 |
96 base::DictionaryValue* file_systems_per_extension_weak = NULL; | 93 base::DictionaryValue* file_systems_per_extension = NULL; |
97 if (!dict_update->GetDictionaryWithoutPathExpansion( | 94 if (!dict_update->GetDictionaryWithoutPathExpansion( |
98 file_system_info.extension_id(), &file_systems_per_extension_weak)) { | 95 file_system_info.extension_id(), &file_systems_per_extension)) { |
99 auto file_systems_per_extension = base::MakeUnique<base::DictionaryValue>(); | 96 file_systems_per_extension = new base::DictionaryValue(); |
100 file_systems_per_extension_weak = file_systems_per_extension.get(); | |
101 dict_update->SetWithoutPathExpansion(file_system_info.extension_id(), | 97 dict_update->SetWithoutPathExpansion(file_system_info.extension_id(), |
102 std::move(file_systems_per_extension)); | 98 file_systems_per_extension); |
103 } | 99 } |
104 | 100 |
105 file_systems_per_extension_weak->SetWithoutPathExpansion( | 101 file_systems_per_extension->SetWithoutPathExpansion( |
106 file_system_info.file_system_id(), std::move(file_system)); | 102 file_system_info.file_system_id(), file_system); |
107 } | 103 } |
108 | 104 |
109 void Registry::ForgetFileSystem(const std::string& extension_id, | 105 void Registry::ForgetFileSystem(const std::string& extension_id, |
110 const std::string& file_system_id) { | 106 const std::string& file_system_id) { |
111 PrefService* const pref_service = profile_->GetPrefs(); | 107 PrefService* const pref_service = profile_->GetPrefs(); |
112 DCHECK(pref_service); | 108 DCHECK(pref_service); |
113 | 109 |
114 DictionaryPrefUpdate dict_update(pref_service, | 110 DictionaryPrefUpdate dict_update(pref_service, |
115 prefs::kFileSystemProviderMounted); | 111 prefs::kFileSystemProviderMounted); |
116 | 112 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 LOG(ERROR) << "Broken preferences detected while updating a tag."; | 271 LOG(ERROR) << "Broken preferences detected while updating a tag."; |
276 return; | 272 return; |
277 } | 273 } |
278 | 274 |
279 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 275 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
280 watcher.last_tag); | 276 watcher.last_tag); |
281 } | 277 } |
282 | 278 |
283 } // namespace file_system_provider | 279 } // namespace file_system_provider |
284 } // namespace chromeos | 280 } // namespace chromeos |
OLD | NEW |