• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/importer/toolbar_importer_utils.h"
6 
7 #include <string>
8 #include <vector>
9 
10 #include "base/string_split.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "googleurl/src/gurl.h"
13 #include "net/base/cookie_store.h"
14 #include "net/url_request/url_request_context_getter.h"
15 
16 namespace {
17 const char kGoogleDomainUrl[] = "http://.google.com/";
18 const char kGoogleDomainSecureCookieId[] = "SID=";
19 const char kSplitStringToken = ';';
20 }
21 
22 namespace toolbar_importer_utils {
23 
IsGoogleGAIACookieInstalled()24 bool IsGoogleGAIACookieInstalled() {
25   net::CookieStore* store =
26       Profile::GetDefaultRequestContext()->DONTUSEME_GetCookieStore();
27   GURL url(kGoogleDomainUrl);
28   net::CookieOptions options;
29   options.set_include_httponly();  // The SID cookie might be httponly.
30   std::string cookies = store->GetCookiesWithOptions(url, options);
31   std::vector<std::string> cookie_list;
32   base::SplitString(cookies, kSplitStringToken, &cookie_list);
33   for (std::vector<std::string>::iterator current = cookie_list.begin();
34        current != cookie_list.end();
35        ++current) {
36     size_t position = (*current).find(kGoogleDomainSecureCookieId);
37     if (0 == position)
38       return true;
39   }
40   return false;
41 }
42 
43 }  // namespace toolbar_importer_utils
44