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

Side by Side Diff: services/catalog/instance.cc

Issue 1910673002: Convert //services from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « services/catalog/instance.h ('k') | services/catalog/reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/catalog/instance.h" 5 #include "services/catalog/instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "services/catalog/entry.h" 8 #include "services/catalog/entry.h"
9 #include "services/catalog/manifest_provider.h" 9 #include "services/catalog/manifest_provider.h"
10 #include "services/catalog/reader.h" 10 #include "services/catalog/reader.h"
11 #include "services/catalog/store.h" 11 #include "services/catalog/store.h"
12 #include "services/shell/public/cpp/names.h" 12 #include "services/shell/public/cpp/names.h"
13 13
14 namespace catalog { 14 namespace catalog {
15 namespace { 15 namespace {
16 16
17 void AddEntry(const Entry& entry, mojo::Array<mojom::EntryPtr>* ary) { 17 void AddEntry(const Entry& entry, mojo::Array<mojom::EntryPtr>* ary) {
18 mojom::EntryPtr entry_ptr(mojom::Entry::New()); 18 mojom::EntryPtr entry_ptr(mojom::Entry::New());
19 entry_ptr->name = entry.name(); 19 entry_ptr->name = entry.name();
20 entry_ptr->display_name = entry.display_name(); 20 entry_ptr->display_name = entry.display_name();
21 ary->push_back(std::move(entry_ptr)); 21 ary->push_back(std::move(entry_ptr));
22 } 22 }
23 23
24 } // namespace 24 } // namespace
25 25
26 //////////////////////////////////////////////////////////////////////////////// 26 ////////////////////////////////////////////////////////////////////////////////
27 // Instance, public: 27 // Instance, public:
28 28
29 Instance::Instance(scoped_ptr<Store> store, Reader* system_reader) 29 Instance::Instance(std::unique_ptr<Store> store, Reader* system_reader)
30 : store_(std::move(store)), 30 : store_(std::move(store)),
31 system_reader_(system_reader), 31 system_reader_(system_reader),
32 weak_factory_(this) {} 32 weak_factory_(this) {}
33 Instance::~Instance() {} 33 Instance::~Instance() {}
34 34
35 void Instance::BindShellResolver( 35 void Instance::BindShellResolver(
36 shell::mojom::ShellResolverRequest request) { 36 shell::mojom::ShellResolverRequest request) {
37 if (system_cache_) 37 if (system_cache_)
38 shell_resolver_bindings_.AddBinding(this, std::move(request)); 38 shell_resolver_bindings_.AddBinding(this, std::move(request));
39 else 39 else
(...skipping 18 matching lines...) Expand all
58 58
59 //////////////////////////////////////////////////////////////////////////////// 59 ////////////////////////////////////////////////////////////////////////////////
60 // Instance, shell::mojom::ShellResolver: 60 // Instance, shell::mojom::ShellResolver:
61 61
62 void Instance::ResolveMojoName(const mojo::String& mojo_name, 62 void Instance::ResolveMojoName(const mojo::String& mojo_name,
63 const ResolveMojoNameCallback& callback) { 63 const ResolveMojoNameCallback& callback) {
64 DCHECK(system_cache_); 64 DCHECK(system_cache_);
65 65
66 std::string type = shell::GetNameType(mojo_name); 66 std::string type = shell::GetNameType(mojo_name);
67 if (type != shell::kNameType_Mojo && type != shell::kNameType_Exe) { 67 if (type != shell::kNameType_Mojo && type != shell::kNameType_Exe) {
68 scoped_ptr<Entry> entry(new Entry(mojo_name)); 68 std::unique_ptr<Entry> entry(new Entry(mojo_name));
69 callback.Run(shell::mojom::ResolveResult::From(*entry)); 69 callback.Run(shell::mojom::ResolveResult::From(*entry));
70 return; 70 return;
71 } 71 }
72 72
73 // TODO(beng): per-user catalogs. 73 // TODO(beng): per-user catalogs.
74 auto entry = system_cache_->find(mojo_name); 74 auto entry = system_cache_->find(mojo_name);
75 if (entry != system_cache_->end()) { 75 if (entry != system_cache_->end()) {
76 callback.Run(shell::mojom::ResolveResult::From(*entry->second)); 76 callback.Run(shell::mojom::ResolveResult::From(*entry->second));
77 return; 77 return;
78 } 78 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (!store_) 142 if (!store_)
143 return; 143 return;
144 const base::ListValue* catalog = store_->GetStore(); 144 const base::ListValue* catalog = store_->GetStore();
145 CHECK(catalog); 145 CHECK(catalog);
146 // TODO(sky): make this handle aliases. 146 // TODO(sky): make this handle aliases.
147 // TODO(beng): implement this properly! 147 // TODO(beng): implement this properly!
148 for (auto it = catalog->begin(); it != catalog->end(); ++it) { 148 for (auto it = catalog->begin(); it != catalog->end(); ++it) {
149 const base::DictionaryValue* dictionary = nullptr; 149 const base::DictionaryValue* dictionary = nullptr;
150 const base::Value* v = *it; 150 const base::Value* v = *it;
151 CHECK(v->GetAsDictionary(&dictionary)); 151 CHECK(v->GetAsDictionary(&dictionary));
152 scoped_ptr<Entry> entry = Entry::Deserialize(*dictionary); 152 std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary);
153 // TODO(beng): user catalog. 153 // TODO(beng): user catalog.
154 if (entry) 154 if (entry)
155 (*system_cache_)[entry->name()] = std::move(entry); 155 (*system_cache_)[entry->name()] = std::move(entry);
156 } 156 }
157 } 157 }
158 158
159 void Instance::SerializeCatalog() { 159 void Instance::SerializeCatalog() {
160 DCHECK(system_cache_); 160 DCHECK(system_cache_);
161 scoped_ptr<base::ListValue> catalog(new base::ListValue); 161 std::unique_ptr<base::ListValue> catalog(new base::ListValue);
162 // TODO(beng): user catalog. 162 // TODO(beng): user catalog.
163 for (const auto& entry : *system_cache_) 163 for (const auto& entry : *system_cache_)
164 catalog->Append(entry.second->Serialize()); 164 catalog->Append(entry.second->Serialize());
165 if (store_) 165 if (store_)
166 store_->UpdateStore(std::move(catalog)); 166 store_->UpdateStore(std::move(catalog));
167 } 167 }
168 168
169 // static 169 // static
170 void Instance::OnReadManifest(base::WeakPtr<Instance> instance, 170 void Instance::OnReadManifest(base::WeakPtr<Instance> instance,
171 const std::string& mojo_name, 171 const std::string& mojo_name,
172 const ResolveMojoNameCallback& callback, 172 const ResolveMojoNameCallback& callback,
173 shell::mojom::ResolveResultPtr result) { 173 shell::mojom::ResolveResultPtr result) {
174 callback.Run(std::move(result)); 174 callback.Run(std::move(result));
175 if (instance) 175 if (instance)
176 instance->SerializeCatalog(); 176 instance->SerializeCatalog();
177 } 177 }
178 178
179 } // namespace catalog 179 } // namespace catalog
OLDNEW
« no previous file with comments | « services/catalog/instance.h ('k') | services/catalog/reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698