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

Side by Side Diff: content/test/test_content_client.cc

Issue 1210153008: Minor refactor to simplify code in content/test/test_content_client.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ios compile Created 5 years, 5 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/test/test_content_client.h" 5 #include "content/test/test_content_client.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 12
13 #if defined(OS_ANDROID) 13 #if defined(OS_ANDROID)
14 #include "base/android/apk_assets.h" 14 #include "base/android/apk_assets.h"
15 #endif 15 #endif
16 16
17 namespace content { 17 namespace content {
18 18
19 TestContentClient::TestContentClient() 19 TestContentClient::TestContentClient()
20 : data_pack_(ui::SCALE_FACTOR_100P) { 20 : data_pack_(ui::SCALE_FACTOR_100P) {
21 // content_shell.pak is not built on iOS as it is not required. 21 // content_shell.pak is not built on iOS as it is not required.
22 #if !defined(OS_IOS) 22 #if !defined(OS_IOS)
23 base::FilePath content_shell_pack_path; 23 base::FilePath content_shell_pack_path;
24 base::File pak_file;
25 base::MemoryMappedFile::Region pak_region;
26
24 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
25 base::MemoryMappedFile::Region region;
26 // Tests that don't yet use .isolate files require loading from within .apk. 28 // Tests that don't yet use .isolate files require loading from within .apk.
27 int fd = base::android::OpenApkAsset("assets/content_shell.pak", &region); 29 pak_file = base::File(
28 if (fd >= 0) { 30 base::android::OpenApkAsset("assets/content_shell.pak", &pak_region));
29 data_pack_.LoadFromFileRegion(base::File(fd), region);
30 return;
31 }
32 31
33 // on Android all pak files are inside the paks folder. 32 // on Android all pak files are inside the paks folder.
34 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path); 33 PathService::Get(base::DIR_ANDROID_APP_DATA, &content_shell_pack_path);
35 content_shell_pack_path = content_shell_pack_path.Append( 34 content_shell_pack_path = content_shell_pack_path.Append(
36 FILE_PATH_LITERAL("paks")); 35 FILE_PATH_LITERAL("paks"));
37 #else 36 #else
38 PathService::Get(base::DIR_MODULE, &content_shell_pack_path); 37 PathService::Get(base::DIR_MODULE, &content_shell_pack_path);
39 #endif 38 #endif // defined(OS_ANDROID)
40 content_shell_pack_path = content_shell_pack_path.Append( 39
41 FILE_PATH_LITERAL("content_shell.pak")); 40 if (pak_file.IsValid()) {
42 data_pack_.LoadFromPath(content_shell_pack_path); 41 data_pack_.LoadFromFileRegion(pak_file.Pass(), pak_region);
43 #endif 42 } else {
43 content_shell_pack_path = content_shell_pack_path.Append(
44 FILE_PATH_LITERAL("content_shell.pak"));
45 data_pack_.LoadFromPath(content_shell_pack_path);
46 }
47 #endif // !defined(OS_IOS)
44 } 48 }
45 49
46 TestContentClient::~TestContentClient() { 50 TestContentClient::~TestContentClient() {
47 } 51 }
48 52
49 std::string TestContentClient::GetUserAgent() const { 53 std::string TestContentClient::GetUserAgent() const {
50 return std::string("TestContentClient"); 54 return std::string("TestContentClient");
51 } 55 }
52 56
53 base::StringPiece TestContentClient::GetDataResource( 57 base::StringPiece TestContentClient::GetDataResource(
54 int resource_id, 58 int resource_id,
55 ui::ScaleFactor scale_factor) const { 59 ui::ScaleFactor scale_factor) const {
56 base::StringPiece resource; 60 base::StringPiece resource;
57 data_pack_.GetStringPiece(resource_id, &resource); 61 data_pack_.GetStringPiece(resource_id, &resource);
58 return resource; 62 return resource;
59 } 63 }
60 64
61 } // namespace content 65 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698