OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/common/extensions/api/storage/storage_schema_manifest_handler.h " | 5 #include "chrome/common/extensions/api/storage/storage_schema_manifest_handler.h " |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 std::string path; | 42 std::string path; |
43 extension->manifest()->GetString(kStorageManagedSchema, &path); | 43 extension->manifest()->GetString(kStorageManagedSchema, &path); |
44 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); | 44 base::FilePath file = base::FilePath::FromUTF8Unsafe(path); |
45 if (file.IsAbsolute() || file.ReferencesParent()) { | 45 if (file.IsAbsolute() || file.ReferencesParent()) { |
46 *error = base::StringPrintf("%s must be a relative path without ..", | 46 *error = base::StringPrintf("%s must be a relative path without ..", |
47 kStorageManagedSchema); | 47 kStorageManagedSchema); |
48 return policy::Schema(); | 48 return policy::Schema(); |
49 } | 49 } |
50 file = extension->path().AppendASCII(path); | 50 file = extension->path().AppendASCII(path); |
51 if (!base::PathExists(file)) { | 51 if (!base::PathExists(file)) { |
52 #ifdef OS_WIN | |
Lei Zhang
2015/09/29 03:16:17
#if defined(OS_WIN), ditto elsewhere, but maybe ju
brucedawson
2015/09/29 21:39:39
Yes. That is much better. It is cleaner and by def
Lei Zhang
2015/09/29 21:42:37
SGTM
| |
53 // FilePath::StringType is std::wstring on Windows | |
54 *error = | |
55 base::StringPrintf("File does not exist: %ls", file.value().c_str()); | |
56 #else | |
52 *error = | 57 *error = |
53 base::StringPrintf("File does not exist: %s", file.value().c_str()); | 58 base::StringPrintf("File does not exist: %s", file.value().c_str()); |
59 #endif | |
54 return policy::Schema(); | 60 return policy::Schema(); |
55 } | 61 } |
56 std::string content; | 62 std::string content; |
57 if (!base::ReadFileToString(file, &content)) { | 63 if (!base::ReadFileToString(file, &content)) { |
64 #ifdef OS_WIN | |
65 // FilePath::StringType is std::wstring on Windows | |
66 *error = base::StringPrintf("Can't read %ls", file.value().c_str()); | |
67 #else | |
58 *error = base::StringPrintf("Can't read %s", file.value().c_str()); | 68 *error = base::StringPrintf("Can't read %s", file.value().c_str()); |
69 #endif | |
59 return policy::Schema(); | 70 return policy::Schema(); |
60 } | 71 } |
61 return policy::Schema::Parse(content, error); | 72 return policy::Schema::Parse(content, error); |
62 } | 73 } |
63 #endif | 74 #endif |
64 | 75 |
65 bool StorageSchemaManifestHandler::Parse(Extension* extension, | 76 bool StorageSchemaManifestHandler::Parse(Extension* extension, |
66 base::string16* error) { | 77 base::string16* error) { |
67 std::string path; | 78 std::string path; |
68 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) { | 79 if (!extension->manifest()->GetString(kStorageManagedSchema, &path)) { |
(...skipping 18 matching lines...) Expand all Loading... | |
87 #else | 98 #else |
88 return true; | 99 return true; |
89 #endif | 100 #endif |
90 } | 101 } |
91 | 102 |
92 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { | 103 const std::vector<std::string> StorageSchemaManifestHandler::Keys() const { |
93 return SingleKey(kStorageManagedSchema); | 104 return SingleKey(kStorageManagedSchema); |
94 } | 105 } |
95 | 106 |
96 } // namespace extensions | 107 } // namespace extensions |
OLD | NEW |