Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/registry.cc

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

Powered by Google App Engine
This is Rietveld 408576698