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

Side by Side Diff: chrome/browser/intents/web_intents_registry.cc

Issue 7511005: Initial version of web intents registry (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Review fixes Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/intents/web_intents_registry.h"
6 #include "chrome/browser/webdata/web_data_service.h"
7
8 // Internal object representing a single intents query.
James Hawkins 2011/08/05 20:47:12 Indentation
groby-ooo-7-16 2011/08/05 20:54:11 Done.
9 struct WebIntentsRegistry::IntentsQuery {
10 // WebDataService returns data asynchronously from a separate thread, so
11 // registry records the query handle until we get called back.
12 QueryID query_id_; // unique query identifier.
James Hawkins 2011/08/05 20:47:12 Indentation
groby-ooo-7-16 2011/08/05 20:54:11 Done.
13 WebDataService::Handle pending_query_; // Underlying data query.
14 Consumer* consumer_; // the consumer for this particular query.
15
16 // TODO(groby): Additional filter data will go here - filtering is handled
17 // per query.
18 };
19
20 WebIntentsRegistry::WebIntentsRegistry() : next_query_id_(0) {}
21
22 WebIntentsRegistry::~WebIntentsRegistry() {
23 // Cancel all pending queries, since we can't handle them any more.
24 for (QueryMap::iterator it(queries.begin()); it != queries.end(); ++it) {
25 wds_->CancelRequest(it->first);
26 delete it->second;
27 }
28 }
29
30 void WebIntentsRegistry::Initialize(scoped_refptr<WebDataService> wds) {
31 wds_ = wds;
32 }
33
34 void WebIntentsRegistry::OnWebDataServiceRequestDone(WebDataService::Handle h,
35 const WDTypedResult* result) {
James Hawkins 2011/08/05 20:47:12 line up params
groby-ooo-7-16 2011/08/05 20:54:11 Done.
36 DCHECK(result);
37 DCHECK(result->GetType() == WEB_INTENTS_RESULT);
38
39 QueryMap::iterator it = queries.find(h);
40 DCHECK(it != queries.end());
41
42 IntentsQuery* query(it->second);
43 DCHECK(query);
44 queries.erase(it);
45
46 // TODO(groby): Filtering goes here.
47 std::vector<WebIntentData> intents = static_cast<
48 const WDResult<std::vector<WebIntentData> >*>(result)->GetValue();
49
50 query->consumer_->OnIntentsQueryDone(query->query_id_, intents);
51 }
52
53 WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders(
54 const string16& action,
55 Consumer* consumer) {
56 DCHECK(consumer);
57 DCHECK(wds_.get());
58
59 IntentsQuery* query = new IntentsQuery;
60 query->query_id_ = next_query_id_++;
61 query->consumer_ = consumer;
62 query->pending_query_ = wds_->GetWebIntents(action, this);
63 queries[query->pending_query_] = query;
64
65 return query->query_id_;
66 }
67
68 void WebIntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) {
69 DCHECK(wds_.get());
70 wds_->AddWebIntent(intent);
71 }
72
73 void WebIntentsRegistry::UnregisterIntentProvider(const WebIntentData& intent) {
74 DCHECK(wds_.get());
75 wds_->RemoveWebIntent(intent);
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698