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

Side by Side Diff: sky/engine/core/loader/MojoLoader.cpp

Issue 650903006: Factor DrainDataPipeJob out of MojoLoader (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "core/loader/MojoLoader.h" 6 #include "core/loader/MojoLoader.h"
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/DocumentInit.h" 10 #include "core/dom/DocumentInit.h"
11 #include "core/frame/LocalDOMWindow.h" 11 #include "core/frame/LocalDOMWindow.h"
12 #include "core/frame/LocalFrame.h" 12 #include "core/frame/LocalFrame.h"
13 #include "mojo/public/cpp/system/data_pipe.h" 13 #include "mojo/public/cpp/system/data_pipe.h"
14 #include "core/loader/FrameLoaderClient.h" 14 #include "core/loader/FrameLoaderClient.h"
15 #include "core/page/Page.h" 15 #include "core/page/Page.h"
16 #include "core/dom/DocumentParser.h" 16 #include "core/dom/DocumentParser.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 using namespace mojo; 20 using namespace mojo;
21 21
22 MojoLoader::MojoLoader(LocalFrame& frame) 22 MojoLoader::MojoLoader(LocalFrame& frame)
23 : m_frame(frame) 23 : m_frame(frame)
24 , m_weakFactory(this)
25 { 24 {
26 } 25 }
27 26
28 void MojoLoader::load(const KURL& url, ScopedDataPipeConsumerHandle responseStre am) 27 void MojoLoader::load(const KURL& url, ScopedDataPipeConsumerHandle responseStre am)
29 { 28 {
30 DocumentInit init(url, &m_frame); 29 DocumentInit init(url, &m_frame);
31 init.withNewRegistrationContext(); 30 init.withNewRegistrationContext();
32 31
33 // FIXME(sky): Poorly named method for creating the FrameView: 32 // FIXME(sky): Poorly named method for creating the FrameView:
34 m_frame.loaderClient()->transitionToCommittedForNewPage(); 33 m_frame.loaderClient()->transitionToCommittedForNewPage();
35 // Only needed for UseCounter, and thus probably can be removed: 34 // Only needed for UseCounter, and thus probably can be removed:
36 m_frame.page()->didCommitLoad(&m_frame); 35 m_frame.page()->didCommitLoad(&m_frame);
37 36
38 m_frame.setDOMWindow(LocalDOMWindow::create(m_frame)); 37 m_frame.setDOMWindow(LocalDOMWindow::create(m_frame));
39 RefPtr<Document> document = m_frame.domWindow()->installNewDocument(init); 38 RefPtr<Document> document = m_frame.domWindow()->installNewDocument(init);
40 // Unclear if we care about DocumentLoadTiming in Sky. 39 // Unclear if we care about DocumentLoadTiming in Sky.
41 document->timing()->markNavigationStart(); 40 document->timing()->markNavigationStart();
42 document->setReadyState(Document::Loading); 41 document->setReadyState(Document::Loading);
43 // FIXME: This should read the Content-Language out of the 42 // FIXME: This should read the Content-Language out of the
44 // response headers and set them on Document::contentLanguage. 43 // response headers and set them on Document::contentLanguage.
45 44
46 document->startParsing(); 45 document->startParsing();
47 m_responseStream = responseStream.Pass(); 46
48 readMore(); 47 m_drainJob = adoptPtr(new DrainDataPipeJob(this, responseStream.Pass()));
49 } 48 }
50 49
51 void MojoLoader::readMore() 50 void MojoLoader::OnDataAvailable(const void* data, size_t numberOfBytes)
52 { 51 {
53 const void* buf = nullptr; 52 m_frame.document()->parser()->appendBytes(static_cast<const char*>(data), nu mberOfBytes);
54 uint32_t buf_size = 0;
55 MojoResult rv = BeginReadDataRaw(m_responseStream.get(),
56 &buf, &buf_size, MOJO_READ_DATA_FLAG_NONE);
57 if (rv == MOJO_RESULT_OK) {
58 m_frame.document()->parser()->appendBytes(static_cast<const char*>(buf), buf_size);
59 EndReadDataRaw(m_responseStream.get(), buf_size);
60 waitToReadMore();
61 } else if (rv == MOJO_RESULT_SHOULD_WAIT) {
62 waitToReadMore();
63 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
64 m_frame.document()->parser()->finish();
65 } else {
66 ASSERT_NOT_REACHED();
67 }
68 } 53 }
69 54
70 void MojoLoader::waitToReadMore() 55 void MojoLoader::OnDataComplete()
71 { 56 {
72 m_handleWatcher.Start(m_responseStream.get(), 57 m_frame.document()->parser()->finish();
73 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
74 base::Bind(&MojoLoader::moreDataReady,m_weakFactory.GetWeakPtr()));
75 }
76
77 void MojoLoader::moreDataReady(MojoResult result)
78 {
79 readMore();
80 } 58 }
81 59
82 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698