| OLD | NEW |
| 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" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Instance, private: | 138 // Instance, private: |
| 139 | 139 |
| 140 void Instance::DeserializeCatalog() { | 140 void Instance::DeserializeCatalog() { |
| 141 DCHECK(system_cache_); | 141 DCHECK(system_cache_); |
| 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 (const auto& v : *catalog) { |
| 149 const base::DictionaryValue* dictionary = nullptr; | 149 const base::DictionaryValue* dictionary = nullptr; |
| 150 const base::Value* v = *it; | |
| 151 CHECK(v->GetAsDictionary(&dictionary)); | 150 CHECK(v->GetAsDictionary(&dictionary)); |
| 152 std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary); | 151 std::unique_ptr<Entry> entry = Entry::Deserialize(*dictionary); |
| 153 // TODO(beng): user catalog. | 152 // TODO(beng): user catalog. |
| 154 if (entry) | 153 if (entry) |
| 155 (*system_cache_)[entry->name()] = std::move(entry); | 154 (*system_cache_)[entry->name()] = std::move(entry); |
| 156 } | 155 } |
| 157 } | 156 } |
| 158 | 157 |
| 159 void Instance::SerializeCatalog() { | 158 void Instance::SerializeCatalog() { |
| 160 DCHECK(system_cache_); | 159 DCHECK(system_cache_); |
| 161 std::unique_ptr<base::ListValue> catalog(new base::ListValue); | 160 std::unique_ptr<base::ListValue> catalog(new base::ListValue); |
| 162 // TODO(beng): user catalog. | 161 // TODO(beng): user catalog. |
| 163 for (const auto& entry : *system_cache_) | 162 for (const auto& entry : *system_cache_) |
| 164 catalog->Append(entry.second->Serialize()); | 163 catalog->Append(entry.second->Serialize()); |
| 165 if (store_) | 164 if (store_) |
| 166 store_->UpdateStore(std::move(catalog)); | 165 store_->UpdateStore(std::move(catalog)); |
| 167 } | 166 } |
| 168 | 167 |
| 169 // static | 168 // static |
| 170 void Instance::OnReadManifest(base::WeakPtr<Instance> instance, | 169 void Instance::OnReadManifest(base::WeakPtr<Instance> instance, |
| 171 const std::string& mojo_name, | 170 const std::string& mojo_name, |
| 172 const ResolveMojoNameCallback& callback, | 171 const ResolveMojoNameCallback& callback, |
| 173 shell::mojom::ResolveResultPtr result) { | 172 shell::mojom::ResolveResultPtr result) { |
| 174 callback.Run(std::move(result)); | 173 callback.Run(std::move(result)); |
| 175 if (instance) | 174 if (instance) |
| 176 instance->SerializeCatalog(); | 175 instance->SerializeCatalog(); |
| 177 } | 176 } |
| 178 | 177 |
| 179 } // namespace catalog | 178 } // namespace catalog |
| OLD | NEW |