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

Side by Side Diff: mojo/apps/js/bindings/waiting_callback.cc

Issue 189453003: Moves around mojo js bindings code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « mojo/apps/js/bindings/waiting_callback.h ('k') | mojo/apps/js/main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/apps/js/bindings/waiting_callback.h"
6
7 #include "gin/per_context_data.h"
8
9 namespace mojo {
10 namespace js {
11
12 namespace {
13
14 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) {
15 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback");
16 }
17
18 } // namespace
19
20 gin::WrapperInfo WaitingCallback::kWrapperInfo = { gin::kEmbedderNativeGin };
21
22 WaitingCallback::WaitingCallback(v8::Isolate* isolate,
23 v8::Handle<v8::Function> callback)
24 : wait_id_() {
25 v8::Handle<v8::Context> context = isolate->GetCurrentContext();
26 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
27 GetWrapper(isolate)->SetHiddenValue(GetHiddenPropertyName(isolate), callback);
28 }
29
30 WaitingCallback::~WaitingCallback() {
31 DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled.";
32 }
33
34 gin::Handle<WaitingCallback> WaitingCallback::Create(
35 v8::Isolate* isolate, v8::Handle<v8::Function> callback) {
36 return gin::CreateHandle(isolate, new WaitingCallback(isolate, callback));
37 }
38
39 // static
40 void WaitingCallback::CallOnHandleReady(void* closure, MojoResult result) {
41 static_cast<WaitingCallback*>(closure)->OnHandleReady(result);
42 }
43
44 void WaitingCallback::OnHandleReady(MojoResult result) {
45 wait_id_ = 0;
46
47 if (!runner_)
48 return;
49
50 gin::Runner::Scope scope(runner_.get());
51 v8::Isolate* isolate = runner_->GetContextHolder()->isolate();
52
53 v8::Handle<v8::Value> hidden_value =
54 GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate));
55 v8::Handle<v8::Function> callback;
56 CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback));
57
58 v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) };
59 runner_->Call(callback, runner_->global(), 1, args);
60 }
61
62 } // namespace js
63 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/apps/js/bindings/waiting_callback.h ('k') | mojo/apps/js/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698