OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/drive/service/fake_drive_service.h" | 5 #include "components/drive/service/fake_drive_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 FakeDriveService::~FakeDriveService() { | 253 FakeDriveService::~FakeDriveService() { |
254 DCHECK(thread_checker_.CalledOnValidThread()); | 254 DCHECK(thread_checker_.CalledOnValidThread()); |
255 } | 255 } |
256 | 256 |
257 bool FakeDriveService::LoadAppListForDriveApi( | 257 bool FakeDriveService::LoadAppListForDriveApi( |
258 const std::string& relative_path) { | 258 const std::string& relative_path) { |
259 DCHECK(thread_checker_.CalledOnValidThread()); | 259 DCHECK(thread_checker_.CalledOnValidThread()); |
260 | 260 |
261 // Load JSON data, which must be a dictionary. | 261 // Load JSON data, which must be a dictionary. |
262 std::unique_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); | 262 std::unique_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); |
263 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); | 263 CHECK_EQ(base::Value::Type::DICTIONARY, value->GetType()); |
264 app_info_value_.reset( | 264 app_info_value_.reset( |
265 static_cast<base::DictionaryValue*>(value.release())); | 265 static_cast<base::DictionaryValue*>(value.release())); |
266 return !!app_info_value_; | 266 return !!app_info_value_; |
267 } | 267 } |
268 | 268 |
269 void FakeDriveService::AddApp(const std::string& app_id, | 269 void FakeDriveService::AddApp(const std::string& app_id, |
270 const std::string& app_name, | 270 const std::string& app_name, |
271 const std::string& product_id, | 271 const std::string& product_id, |
272 const std::string& create_url, | 272 const std::string& create_url, |
273 bool is_removable) { | 273 bool is_removable) { |
274 if (app_json_template_.empty()) { | 274 if (app_json_template_.empty()) { |
275 base::FilePath path = | 275 base::FilePath path = |
276 test_util::GetTestFilePath("drive/applist_app_template.json"); | 276 test_util::GetTestFilePath("drive/applist_app_template.json"); |
277 CHECK(base::ReadFileToString(path, &app_json_template_)); | 277 CHECK(base::ReadFileToString(path, &app_json_template_)); |
278 } | 278 } |
279 | 279 |
280 std::string app_json = app_json_template_; | 280 std::string app_json = app_json_template_; |
281 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$AppId", app_id); | 281 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$AppId", app_id); |
282 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$AppName", app_name); | 282 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$AppName", app_name); |
283 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$ProductId", product_id); | 283 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$ProductId", product_id); |
284 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$CreateUrl", create_url); | 284 base::ReplaceSubstringsAfterOffset(&app_json, 0, "$CreateUrl", create_url); |
285 base::ReplaceSubstringsAfterOffset( | 285 base::ReplaceSubstringsAfterOffset( |
286 &app_json, 0, "$Removable", is_removable ? "true" : "false"); | 286 &app_json, 0, "$Removable", is_removable ? "true" : "false"); |
287 | 287 |
288 JSONStringValueDeserializer json(app_json); | 288 JSONStringValueDeserializer json(app_json); |
289 std::string error_message; | 289 std::string error_message; |
290 std::unique_ptr<base::Value> value(json.Deserialize(NULL, &error_message)); | 290 std::unique_ptr<base::Value> value(json.Deserialize(NULL, &error_message)); |
291 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); | 291 CHECK_EQ(base::Value::Type::DICTIONARY, value->GetType()); |
292 | 292 |
293 base::ListValue* item_list; | 293 base::ListValue* item_list; |
294 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); | 294 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
295 item_list->Append(std::move(value)); | 295 item_list->Append(std::move(value)); |
296 } | 296 } |
297 | 297 |
298 void FakeDriveService::RemoveAppByProductId(const std::string& product_id) { | 298 void FakeDriveService::RemoveAppByProductId(const std::string& product_id) { |
299 base::ListValue* item_list; | 299 base::ListValue* item_list; |
300 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); | 300 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
301 for (size_t i = 0; i < item_list->GetSize(); ++i) { | 301 for (size_t i = 0; i < item_list->GetSize(); ++i) { |
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 NOTREACHED(); | 1790 NOTREACHED(); |
1791 return std::unique_ptr<BatchRequestConfiguratorInterface>(); | 1791 return std::unique_ptr<BatchRequestConfiguratorInterface>(); |
1792 } | 1792 } |
1793 | 1793 |
1794 void FakeDriveService::NotifyObservers() { | 1794 void FakeDriveService::NotifyObservers() { |
1795 for (auto& observer : change_observers_) | 1795 for (auto& observer : change_observers_) |
1796 observer.OnNewChangeAvailable(); | 1796 observer.OnNewChangeAvailable(); |
1797 } | 1797 } |
1798 | 1798 |
1799 } // namespace drive | 1799 } // namespace drive |
OLD | NEW |