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

Side by Side Diff: mojo/fetcher/local_fetcher.cc

Issue 1442203002: Fetch Mandoline components from Google Storage as needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use the new 'latest' version folder on Google Storage. Created 5 years, 1 month 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 | « mojo/fetcher/local_fetcher.h ('k') | mojo/package_manager/package_manager_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/fetcher/local_fetcher.h" 5 #include "mojo/fetcher/local_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
8 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
9 #include "base/format_macros.h" 10 #include "base/format_macros.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
14 #include "mojo/common/common_type_converters.h" 15 #include "mojo/common/common_type_converters.h"
15 #include "mojo/common/data_pipe_utils.h" 16 #include "mojo/common/data_pipe_utils.h"
16 #include "mojo/common/url_type_converters.h" 17 #include "mojo/common/url_type_converters.h"
17 #include "mojo/services/network/public/interfaces/network_service.mojom.h" 18 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
19 #include "mojo/shell/switches.h"
18 #include "mojo/util/filename_util.h" 20 #include "mojo/util/filename_util.h"
19 #include "url/url_util.h" 21 #include "url/url_util.h"
20 22
21 namespace mojo { 23 namespace mojo {
22 namespace fetcher { 24 namespace fetcher {
23 25
24 namespace { 26 namespace {
25 void IgnoreResult(bool result) { 27 void IgnoreResult(bool result) {
26 } 28 }
27 29
28 } // namespace 30 } // namespace
29 31
30 // A loader for local files. 32 // A loader for local files.
31 LocalFetcher::LocalFetcher(NetworkService* network_service, 33 LocalFetcher::LocalFetcher(NetworkService* network_service,
32 const GURL& url, 34 const GURL& url,
33 const GURL& url_without_query, 35 const GURL& url_without_query,
36 const base::FilePath& shell_file_root,
34 const FetchCallback& loader_callback) 37 const FetchCallback& loader_callback)
35 : Fetcher(loader_callback), 38 : Fetcher(loader_callback),
36 url_(url), 39 url_(url),
37 path_(util::UrlToFilePath(url_without_query)) { 40 path_(util::UrlToFilePath(url_without_query)),
41 shell_file_root_(shell_file_root) {
38 TRACE_EVENT1("mojo_shell", "LocalFetcher::LocalFetcher", "url", url.spec()); 42 TRACE_EVENT1("mojo_shell", "LocalFetcher::LocalFetcher", "url", url.spec());
39 const std::string ext(base::FilePath(path_.Extension()).AsUTF8Unsafe()); 43 const std::string ext(base::FilePath(path_.Extension()).AsUTF8Unsafe());
40 if (network_service && !base::EqualsCaseInsensitiveASCII(ext, ".mojo")) { 44 if (network_service && !base::EqualsCaseInsensitiveASCII(ext, ".mojo")) {
41 network_service->GetMimeTypeFromFile( 45 network_service->GetMimeTypeFromFile(
42 path_.AsUTF8Unsafe(), 46 path_.AsUTF8Unsafe(),
43 base::Bind(&LocalFetcher::GetMimeTypeFromFileCallback, 47 base::Bind(&LocalFetcher::GetMimeTypeFromFileCallback,
44 base::Unretained(this))); 48 base::Unretained(this)));
45 } else { 49 } else {
46 loader_callback_.Run(make_scoped_ptr(this)); 50 loader_callback_.Run(make_scoped_ptr(this));
47 } 51 }
48 } 52 }
49 53
54 LocalFetcher::~LocalFetcher() {}
55
50 void LocalFetcher::GetMimeTypeFromFileCallback(const mojo::String& mime_type) { 56 void LocalFetcher::GetMimeTypeFromFileCallback(const mojo::String& mime_type) {
51 mime_type_ = mime_type.To<std::string>(); 57 mime_type_ = mime_type.To<std::string>();
52 loader_callback_.Run(make_scoped_ptr(this)); 58 loader_callback_.Run(make_scoped_ptr(this));
53 } 59 }
54 60
55 const GURL& LocalFetcher::GetURL() const { 61 const GURL& LocalFetcher::GetURL() const {
56 return url_; 62 return url_;
57 } 63 }
58 64
59 GURL LocalFetcher::GetRedirectURL() const { 65 GURL LocalFetcher::GetRedirectURL() const {
66 // Use Mandoline's Google Storage bucket if the Mojo component does not exist.
67 // TODO(msw): Integrate with Mandoline's component updater? crbug.com/479169
68 // TODO(msw): Integrate with planned Omaha fetcher and updater work.
69 // TODO(msw): Support fetching apps with resource files.
70 // TODO(msw): Handle broken URLs. (unavailable component files, etc.)
71 // TODO(msw): Avoid kPredictableAppFilenames switch? (need executable bit set)
72 if (!base::PathExists(path_) && shell_file_root_.IsParent(path_) &&
73 path_.MatchesExtension(FILE_PATH_LITERAL(".mojo")) &&
74 base::CommandLine::ForCurrentProcess()->HasSwitch(
75 switches::kPredictableAppFilenames)) {
76 GURL url("https://storage.googleapis.com/mandoline/");
77 const std::string version("latest/");
78 #if defined(OS_WIN)
79 const std::string platform("win/");
80 #elif defined(OS_LINUX)
81 const std::string platform("linux/");
82 #else
83 const std::string platform("unknown/");
84 #endif
85 // Get the app path relative to the shell (and Google Storage) file root.
86 base::FilePath app_path;
87 bool result = shell_file_root_.AppendRelativePath(path_, &app_path);
88 DCHECK(result);
89 url = url.Resolve(version).Resolve(platform).Resolve(app_path.value());
90 return url;
91 }
60 return GURL::EmptyGURL(); 92 return GURL::EmptyGURL();
61 } 93 }
62 94
63 GURL LocalFetcher::GetRedirectReferer() const { 95 GURL LocalFetcher::GetRedirectReferer() const {
64 return GURL::EmptyGURL(); 96 return GURL::EmptyGURL();
65 } 97 }
66 98
67 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner, 99 URLResponsePtr LocalFetcher::AsURLResponse(base::TaskRunner* task_runner,
68 uint32_t skip) { 100 uint32_t skip) {
69 URLResponsePtr response(URLResponse::New()); 101 URLResponsePtr response(URLResponse::New());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ReadFileToString(path_, &start_of_file, kMaxShebangLength); 139 ReadFileToString(path_, &start_of_file, kMaxShebangLength);
108 size_t return_position = start_of_file.find('\n'); 140 size_t return_position = start_of_file.find('\n');
109 if (return_position == std::string::npos) 141 if (return_position == std::string::npos)
110 return false; 142 return false;
111 *line = start_of_file.substr(0, return_position + 1); 143 *line = start_of_file.substr(0, return_position + 1);
112 return true; 144 return true;
113 } 145 }
114 146
115 } // namespace fetcher 147 } // namespace fetcher
116 } // namespace mojo 148 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/fetcher/local_fetcher.h ('k') | mojo/package_manager/package_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698