Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/arc/test/fake_app_instance.h" | 5 #include "components/arc/test/fake_app_instance.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "mojo/common/common_type_converters.h" | |
| 19 | 18 |
| 20 namespace mojo { | 19 namespace mojo { |
| 21 | 20 |
| 22 template <> | 21 template <> |
| 23 struct TypeConverter<arc::mojom::AppInfoPtr, arc::mojom::AppInfo> { | 22 struct TypeConverter<arc::mojom::AppInfoPtr, arc::mojom::AppInfo> { |
| 24 static arc::mojom::AppInfoPtr Convert(const arc::mojom::AppInfo& app_info) { | 23 static arc::mojom::AppInfoPtr Convert(const arc::mojom::AppInfo& app_info) { |
| 25 return app_info.Clone(); | 24 return app_info.Clone(); |
| 26 } | 25 } |
| 27 }; | 26 }; |
| 28 | 27 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 } | 106 } |
| 108 | 107 |
| 109 bool FakeAppInstance::GenerateAndSendIcon(const mojom::AppInfo& app, | 108 bool FakeAppInstance::GenerateAndSendIcon(const mojom::AppInfo& app, |
| 110 mojom::ScaleFactor scale_factor, | 109 mojom::ScaleFactor scale_factor, |
| 111 std::string* png_data_as_string) { | 110 std::string* png_data_as_string) { |
| 112 if (!GetFakeIcon(scale_factor, png_data_as_string)) { | 111 if (!GetFakeIcon(scale_factor, png_data_as_string)) { |
| 113 return false; | 112 return false; |
| 114 } | 113 } |
| 115 | 114 |
| 116 app_host_->OnAppIcon(app.package_name, app.activity, scale_factor, | 115 app_host_->OnAppIcon(app.package_name, app.activity, scale_factor, |
| 117 mojo::Array<uint8_t>::From(*png_data_as_string)); | 116 std::vector<uint8_t>(png_data_as_string->begin(), |
|
yzshen1
2017/01/06 19:38:37
It would be nice to avoid such conversion by using
| |
| 117 png_data_as_string->end())); | |
| 118 | 118 |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool FakeAppInstance::GetFakeIcon(mojom::ScaleFactor scale_factor, | 122 bool FakeAppInstance::GetFakeIcon(mojom::ScaleFactor scale_factor, |
| 123 std::string* png_data_as_string) { | 123 std::string* png_data_as_string) { |
| 124 CHECK(png_data_as_string != nullptr); | 124 CHECK(png_data_as_string != nullptr); |
| 125 std::string icon_file_name; | 125 std::string icon_file_name; |
| 126 switch (scale_factor) { | 126 switch (scale_factor) { |
| 127 case mojom::ScaleFactor::SCALE_FACTOR_100P: | 127 case mojom::ScaleFactor::SCALE_FACTOR_100P: |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 } | 241 } |
| 242 | 242 |
| 243 void FakeAppInstance::RequestIcon(const std::string& icon_resource_id, | 243 void FakeAppInstance::RequestIcon(const std::string& icon_resource_id, |
| 244 arc::mojom::ScaleFactor scale_factor, | 244 arc::mojom::ScaleFactor scale_factor, |
| 245 const RequestIconCallback& callback) { | 245 const RequestIconCallback& callback) { |
| 246 shortcut_icon_requests_.push_back( | 246 shortcut_icon_requests_.push_back( |
| 247 base::MakeUnique<ShortcutIconRequest>(icon_resource_id, scale_factor)); | 247 base::MakeUnique<ShortcutIconRequest>(icon_resource_id, scale_factor)); |
| 248 | 248 |
| 249 std::string png_data_as_string; | 249 std::string png_data_as_string; |
| 250 if (GetFakeIcon(scale_factor, &png_data_as_string)) { | 250 if (GetFakeIcon(scale_factor, &png_data_as_string)) { |
| 251 callback.Run(mojo::Array<uint8_t>::From(png_data_as_string)); | 251 callback.Run(std::vector<uint8_t>(png_data_as_string.begin(), |
| 252 png_data_as_string.end())); | |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 void FakeAppInstance::RemoveCachedIcon(const std::string& icon_resource_id) {} | 256 void FakeAppInstance::RemoveCachedIcon(const std::string& icon_resource_id) {} |
| 256 | 257 |
| 257 } // namespace arc | 258 } // namespace arc |
| OLD | NEW |