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

Side by Side Diff: sky/engine/core/script/dart_loader.cc

Issue 926753002: Improve DartLoader error handling. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove saw_error Created 5 years, 10 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 | « sky/engine/core/script/dart_loader.h ('k') | sky/engine/tonic/dart_error.cc » ('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 "sky/engine/config.h" 5 #include "sky/engine/config.h"
6 #include "sky/engine/core/script/dart_loader.h" 6 #include "sky/engine/core/script/dart_loader.h"
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "mojo/common/data_pipe_drainer.h" 9 #include "mojo/common/data_pipe_drainer.h"
10 #include "sky/engine/core/script/dart_dependency_catcher.h" 10 #include "sky/engine/core/script/dart_dependency_catcher.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const KURL& url() const { return url_; } 52 const KURL& url() const { return url_; }
53 53
54 protected: 54 protected:
55 DartLoader* loader_; 55 DartLoader* loader_;
56 // TODO(abarth): Should we be using SharedBuffer to buffer the data? 56 // TODO(abarth): Should we be using SharedBuffer to buffer the data?
57 Vector<uint8_t> buffer_; 57 Vector<uint8_t> buffer_;
58 58
59 private: 59 private:
60 // MojoFetcher::Client 60 // MojoFetcher::Client
61 void OnReceivedResponse(mojo::URLResponsePtr response) override { 61 void OnReceivedResponse(mojo::URLResponsePtr response) override {
62 // TODO(abarth): Handle network errors. 62 if (response->status_code != 200) {
63 loader_->DidFailJob(this);
64 return;
65 }
63 drainer_ = adoptPtr(new DataPipeDrainer(this, response->body.Pass())); 66 drainer_ = adoptPtr(new DataPipeDrainer(this, response->body.Pass()));
64 } 67 }
65 68
66 // DataPipeDrainer::Client 69 // DataPipeDrainer::Client
67 void OnDataAvailable(const void* data, size_t num_bytes) override { 70 void OnDataAvailable(const void* data, size_t num_bytes) override {
68 buffer_.append(static_cast<const uint8_t*>(data), num_bytes); 71 buffer_.append(static_cast<const uint8_t*>(data), num_bytes);
69 } 72 }
70 // Subclasses must implement OnDataComplete. 73 // Subclasses must implement OnDataComplete.
71 74
72 KURL url_; 75 KURL url_;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 callback.Run(); 171 callback.Run();
169 } 172 }
170 173
171 private: 174 private:
172 DartLoader& loader_; 175 DartLoader& loader_;
173 OwnPtr<DartDependencyCatcher> catcher_; 176 OwnPtr<DartDependencyCatcher> catcher_;
174 DartDependency* resolved_dependency_; 177 DartDependency* resolved_dependency_;
175 }; 178 };
176 179
177 DartLoader::DartLoader(DartState* dart_state) 180 DartLoader::DartLoader(DartState* dart_state)
178 : dart_state_(dart_state->GetWeakPtr()), dependency_catcher_(nullptr) { 181 : dart_state_(dart_state->GetWeakPtr()),
182 dependency_catcher_(nullptr) {
abarth-chromium 2015/02/14 00:28:06 git cl format will probably undo this change.
179 } 183 }
180 184
181 DartLoader::~DartLoader() { 185 DartLoader::~DartLoader() {
182 } 186 }
183 187
184 Dart_Handle DartLoader::HandleLibraryTag(Dart_LibraryTag tag, 188 Dart_Handle DartLoader::HandleLibraryTag(Dart_LibraryTag tag,
185 Dart_Handle library, 189 Dart_Handle library,
186 Dart_Handle url) { 190 Dart_Handle url) {
187 DCHECK(Dart_IsLibrary(library)); 191 DCHECK(Dart_IsLibrary(library));
188 DCHECK(Dart_IsString(url)); 192 DCHECK(Dart_IsString(url));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 WatcherSignaler watcher_signaler(*this, job); 259 WatcherSignaler watcher_signaler(*this, job);
256 260
257 LogIfError(Dart_LoadSource( 261 LogIfError(Dart_LoadSource(
258 Dart_HandleFromPersistent(job->library()), 262 Dart_HandleFromPersistent(job->library()),
259 StringToDart(dart_state_.get(), job->url().string()), 263 StringToDart(dart_state_.get(), job->url().string()),
260 Dart_NewStringFromUTF8(buffer.data(), buffer.size()), 0, 0)); 264 Dart_NewStringFromUTF8(buffer.data(), buffer.size()), 0, 0));
261 265
262 jobs_.remove(job); 266 jobs_.remove(job);
263 } 267 }
264 268
269 void DartLoader::DidFailJob(Job* job) {
270 DCHECK(dart_state_);
271 DartIsolateScope scope(dart_state_->isolate());
272 DartApiScope api_scope;
273
274 WatcherSignaler watcher_signaler(*this, job);
275
276 LOG(ERROR) << "Library Load failed: " << job->url().string().utf8().data();
277 // TODO(eseidel): Call Dart_LibraryHandleError in the SourceJob case?
278
279 jobs_.remove(job);
280 }
281
265 } // namespace blink 282 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/script/dart_loader.h ('k') | sky/engine/tonic/dart_error.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698