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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.h"
9 #include "chrome/browser/google/google_brand.h"
10 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
15 #include "components/signin/core/browser/profile_identity_provider.h"
16 #include "components/signin/core/browser/signin_manager.h"
17 #include "components/update_client/update_query_params.h"
18 #include "extensions/browser/updater/extension_downloader.h"
19 #include "google_apis/gaia/identity_provider.h"
21 using extensions::ExtensionDownloader
;
22 using extensions::ExtensionDownloaderDelegate
;
23 using update_client::UpdateQueryParams
;
25 scoped_ptr
<ExtensionDownloader
>
26 ChromeExtensionDownloaderFactory::CreateForRequestContext(
27 net::URLRequestContextGetter
* request_context
,
28 ExtensionDownloaderDelegate
* delegate
) {
29 scoped_ptr
<ExtensionDownloader
> downloader(
30 new ExtensionDownloader(delegate
, request_context
));
31 #if defined(GOOGLE_CHROME_BUILD)
33 google_brand::GetBrand(&brand
);
34 if (!brand
.empty() && !google_brand::IsOrganic(brand
))
35 downloader
->set_brand_code(brand
);
36 #endif // defined(GOOGLE_CHROME_BUILD)
37 downloader
->set_manifest_query_params(
38 UpdateQueryParams::Get(UpdateQueryParams::CRX
));
39 downloader
->set_ping_enabled_domain("google.com");
40 downloader
->set_enable_extra_update_metrics(
41 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
42 return downloader
.Pass();
45 scoped_ptr
<ExtensionDownloader
>
46 ChromeExtensionDownloaderFactory::CreateForProfile(
48 ExtensionDownloaderDelegate
* delegate
) {
49 scoped_ptr
<IdentityProvider
> identity_provider(new ProfileIdentityProvider(
50 SigninManagerFactory::GetForProfile(profile
),
51 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
52 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile
)));
53 scoped_ptr
<ExtensionDownloader
> downloader
=
54 CreateForRequestContext(profile
->GetRequestContext(), delegate
);
55 downloader
->SetWebstoreIdentityProvider(identity_provider
.Pass());
56 return downloader
.Pass();