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 "sky/shell/dart/dart_library_provider_files.h" | 5 #include "sky/shell/dart/dart_library_provider_files.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 const base::FilePath& package_root) | 43 const base::FilePath& package_root) |
44 : package_root_(package_root) { | 44 : package_root_(package_root) { |
45 CHECK(base::DirectoryExists(package_root_)) << "Invalid --package-root " | 45 CHECK(base::DirectoryExists(package_root_)) << "Invalid --package-root " |
46 << "\"" << package_root_.LossyDisplayName() << "\""; | 46 << "\"" << package_root_.LossyDisplayName() << "\""; |
47 } | 47 } |
48 | 48 |
49 DartLibraryProviderFiles::~DartLibraryProviderFiles() { | 49 DartLibraryProviderFiles::~DartLibraryProviderFiles() { |
50 } | 50 } |
51 | 51 |
52 void DartLibraryProviderFiles::GetLibraryAsStream( | 52 void DartLibraryProviderFiles::GetLibraryAsStream( |
53 const String& name, | 53 const std::string& name, |
54 blink::DataPipeConsumerCallback callback) { | 54 blink::DataPipeConsumerCallback callback) { |
55 mojo::DataPipe pipe; | 55 mojo::DataPipe pipe; |
56 callback.Run(pipe.consumer_handle.Pass()); | 56 callback.Run(pipe.consumer_handle.Pass()); |
57 | 57 |
58 base::FilePath source(name.toUTF8()); | 58 base::FilePath source(name); |
59 scoped_refptr<base::TaskRunner> runner = | 59 scoped_refptr<base::TaskRunner> runner = |
60 base::WorkerPool::GetTaskRunner(true); | 60 base::WorkerPool::GetTaskRunner(true); |
61 mojo::common::CopyFromFile(source, pipe.producer_handle.Pass(), 0, | 61 mojo::common::CopyFromFile(source, pipe.producer_handle.Pass(), 0, |
62 runner.get(), base::Bind(&CopyComplete, source)); | 62 runner.get(), base::Bind(&CopyComplete, source)); |
63 } | 63 } |
64 | 64 |
65 std::string DartLibraryProviderFiles::CanonicalizePackageURL(std::string url) { | 65 std::string DartLibraryProviderFiles::CanonicalizePackageURL(std::string url) { |
66 DCHECK(StartsWithASCII(url, "package:", true)); | 66 DCHECK(StartsWithASCII(url, "package:", true)); |
67 ReplaceFirstSubstringAfterOffset(&url, 0, "package:", ""); | 67 ReplaceFirstSubstringAfterOffset(&url, 0, "package:", ""); |
68 return package_root_.Append(url).AsUTF8Unsafe(); | 68 return package_root_.Append(url).AsUTF8Unsafe(); |
69 } | 69 } |
70 | 70 |
71 Dart_Handle DartLibraryProviderFiles::CanonicalizeURL(Dart_Handle library, | 71 Dart_Handle DartLibraryProviderFiles::CanonicalizeURL(Dart_Handle library, |
72 Dart_Handle url) { | 72 Dart_Handle url) { |
73 std::string string = blink::StdStringFromDart(url); | 73 std::string string = blink::StdStringFromDart(url); |
74 if (StartsWithASCII(string, "dart:", true)) | 74 if (StartsWithASCII(string, "dart:", true)) |
75 return url; | 75 return url; |
76 if (StartsWithASCII(string, "package:", true)) | 76 if (StartsWithASCII(string, "package:", true)) |
77 return blink::StdStringToDart(CanonicalizePackageURL(string)); | 77 return blink::StdStringToDart(CanonicalizePackageURL(string)); |
78 base::FilePath base_path(blink::StdStringFromDart(Dart_LibraryUrl(library))); | 78 base::FilePath base_path(blink::StdStringFromDart(Dart_LibraryUrl(library))); |
79 base::FilePath resolved_path = base_path.DirName().Append(string); | 79 base::FilePath resolved_path = base_path.DirName().Append(string); |
80 base::FilePath normalized_path = SimplifyPath(resolved_path); | 80 base::FilePath normalized_path = SimplifyPath(resolved_path); |
81 return blink::StdStringToDart(normalized_path.AsUTF8Unsafe()); | 81 return blink::StdStringToDart(normalized_path.AsUTF8Unsafe()); |
82 } | 82 } |
83 | 83 |
84 } // namespace shell | 84 } // namespace shell |
85 } // namespace sky | 85 } // namespace sky |
OLD | NEW |