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

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

Issue 8144013: Add a check to the registry before the intent infobar is shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix provider to service in comments. Created 9 years, 1 month 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 | « chrome/browser/intents/web_intents_registry.h ('k') | chrome/browser/ui/browser.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 (c) 2011 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/intents/web_intents_registry.h" 5 #include "chrome/browser/intents/web_intents_registry.h"
6 6
7 #include "base/callback.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/webdata/web_data_service.h" 9 #include "chrome/browser/webdata/web_data_service.h"
9 #include "net/base/mime_util.h" 10 #include "net/base/mime_util.h"
10 11
11 namespace { 12 namespace {
12 13
13 // Compares two mime types for equality. Supports wild cards in both 14 // Compares two mime types for equality. Supports wild cards in both
14 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. 15 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'.
15 bool MimeTypesAreEqual(const string16& type1, const string16& type2) { 16 bool MimeTypesAreEqual(const string16& type1, const string16& type2) {
16 // We don't have a MIME matcher that allows patterns on both sides 17 // We don't have a MIME matcher that allows patterns on both sides
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 IntentsQuery* query = new IntentsQuery; 132 IntentsQuery* query = new IntentsQuery;
132 query->query_id_ = next_query_id_++; 133 query->query_id_ = next_query_id_++;
133 query->consumer_ = consumer; 134 query->consumer_ = consumer;
134 query->type_ = ASCIIToUTF16("*"); 135 query->type_ = ASCIIToUTF16("*");
135 query->pending_query_ = wds_->GetAllWebIntentServices(this); 136 query->pending_query_ = wds_->GetAllWebIntentServices(this);
136 queries_[query->pending_query_] = query; 137 queries_[query->pending_query_] = query;
137 138
138 return query->query_id_; 139 return query->query_id_;
139 } 140 }
140 141
142 // Trampoline consumer for calls to IntentProviderExists. Forwards existence
143 // of the provided |service| to the provided |callback|.
144 class ProviderCheckConsumer : public WebIntentsRegistry::Consumer {
145 public:
146 ProviderCheckConsumer(const WebIntentServiceData& service,
147 const base::Callback<void(bool)>& callback)
148 : callback_(callback),
149 service_(service) {}
150 virtual ~ProviderCheckConsumer() {}
151
152 // Gets the list of all providers for a particular action. Check them all
153 // to see if |provider_| is already registered.
154 virtual void OnIntentsQueryDone(
155 WebIntentsRegistry::QueryID id,
156 const WebIntentsRegistry::IntentServiceList& list) OVERRIDE {
157 scoped_ptr<ProviderCheckConsumer> self_deleter(this);
158
159 for (WebIntentsRegistry::IntentServiceList::const_iterator i = list.begin();
160 i != list.end(); ++i) {
161 if (*i == service_) {
162 callback_.Run(true);
163 return;
164 }
165 }
166
167 callback_.Run(false);
168 }
169
170 private:
171 base::Callback<void(bool)> callback_;
172 WebIntentServiceData service_;
173 };
174
175 WebIntentsRegistry::QueryID WebIntentsRegistry::IntentProviderExists(
176 const WebIntentServiceData& provider,
177 const base::Callback<void(bool)>& callback) {
178 IntentsQuery* query = new IntentsQuery;
179 query->query_id_ = next_query_id_++;
180 query->type_ = ASCIIToUTF16("*");
181 query->consumer_ = new ProviderCheckConsumer(provider, callback);
182 query->pending_query_ = wds_->GetWebIntentServicesForURL(
183 UTF8ToUTF16(provider.service_url.spec()), this);
184 queries_[query->pending_query_] = query;
185
186 return query->query_id_;
187 }
188
141 void WebIntentsRegistry::RegisterIntentProvider( 189 void WebIntentsRegistry::RegisterIntentProvider(
142 const WebIntentServiceData& service) { 190 const WebIntentServiceData& service) {
143 DCHECK(wds_.get()); 191 DCHECK(wds_.get());
144 wds_->AddWebIntentService(service); 192 wds_->AddWebIntentService(service);
145 } 193 }
146 194
147 void WebIntentsRegistry::UnregisterIntentProvider( 195 void WebIntentsRegistry::UnregisterIntentProvider(
148 const WebIntentServiceData& service) { 196 const WebIntentServiceData& service) {
149 DCHECK(wds_.get()); 197 DCHECK(wds_.get());
150 wds_->RemoveWebIntentService(service); 198 wds_->RemoveWebIntentService(service);
151 } 199 }
OLDNEW
« no previous file with comments | « chrome/browser/intents/web_intents_registry.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698