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

Unified Diff: third_party/WebKit/Source/modules/budget/BudgetService.cpp

Issue 2231873002: Added budget_service.mojom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@budget_api
Patch Set: code review comments Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/budget/BudgetService.cpp
diff --git a/third_party/WebKit/Source/modules/budget/BudgetService.cpp b/third_party/WebKit/Source/modules/budget/BudgetService.cpp
index 52ae315ddafb453f58e4b13fade28daa1d8c6a25..7e0f955ac2bf0764a97cb1aa398c438c25ede7a6 100644
--- a/third_party/WebKit/Source/modules/budget/BudgetService.cpp
+++ b/third_party/WebKit/Source/modules/budget/BudgetService.cpp
@@ -9,21 +9,71 @@
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
+#include "modules/budget/BudgetChunk.h"
+#include "public/platform/InterfaceProvider.h"
+#include "public/platform/Platform.h"
+#include "public/platform/modules/budget_service/budget_service.mojom-blink.h"
namespace blink {
-BudgetService::BudgetService() {}
+BudgetService::BudgetService()
+{
+ Platform::current()->interfaceProvider()->getInterface(mojo::GetProxy(&m_service));
+}
+
+BudgetService::~BudgetService()
+{
+}
+
+ScriptPromise BudgetService::getCost(ScriptState* scriptState, const AtomicString& /* actionType */)
+{
+ DCHECK(m_service);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ // TODO(harkness): Map the actionType to OperationType.
+ mojom::blink::OperationType type = mojom::blink::OperationType::SILENT_PUSH;
+ m_service->GetCost(type, convertToBaseCallback(WTF::bind(&BudgetService::asyncGetCost, wrapPersistent(this), wrapPersistent(resolver))));
+ return promise;
+}
-ScriptPromise BudgetService::getCost(ScriptState* scriptState, const AtomicString& actionType)
+void BudgetService::asyncGetCost(ScriptPromiseResolver* resolver, double cost) const
{
- // TODO(harkness): Trigger the cost calculation.
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "Not yet implemented"));
+ resolver->resolve(cost);
}
ScriptPromise BudgetService::getBudget(ScriptState* scriptState)
{
- // TODO(harkness): Trigger the budget calculation.
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "Not yet implemented"));
+ DCHECK(m_service);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ // TODO(harkness): Get the origin from the ScriptState.
+ RefPtr<SecurityOrigin> origin(scriptState->getExecutionContext()->getSecurityOrigin());
+ m_service->GetBudget(origin, convertToBaseCallback(WTF::bind(&BudgetService::asyncGetBudget, wrapPersistent(this), unretained(scriptState), wrapPersistent(resolver))));
harkness 2016/08/15 01:06:39 I couldn't find documentation about when to use un
+ return promise;
+}
+
+void BudgetService::asyncGetBudget(ScriptState* scriptState, ScriptPromiseResolver* resolver, const mojo::WTFArray<mojom::blink::BudgetStatePtr> expectations) const
+{
+
+ Vector<v8::Local<v8::Value>> budget;
+ if (!scriptState) {
+ resolver->resolve(budget);
+ return;
+ }
+
+ // Copy the chunks into the budget array.
+ budget.grow(expectations.size());
+ for (uint i = 0; i < expectations.size(); i++) {
+ BudgetChunk chunk;
+ chunk.setAmount(expectations[i]->budget_at);
+ chunk.setExpiration(expectations[i]->time);
+
+ budget[i] = freezeV8Object(toV8(chunk, scriptState), scriptState->isolate());
harkness 2016/08/15 01:06:39 This line crashes, uploading so you can take a loo
+ }
+
+ resolver->resolve(budget);
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/budget/BudgetService.h ('k') | third_party/WebKit/Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698