Home | History | Annotate | Download | only in cloud_print
      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/printing/cloud_print/cloud_print_url.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/logging.h"
      9 #include "chrome/browser/prefs/pref_service.h"
     10 #include "chrome/browser/profiles/profile.h"
     11 #include "chrome/common/chrome_switches.h"
     12 #include "chrome/common/pref_names.h"
     13 #include "googleurl/src/gurl.h"
     14 
     15 const char kDefaultCloudPrintServiceURL[] = "https://www.google.com/cloudprint";
     16 const char kLearnMoreURL[] =
     17     "https://www.google.com/support/cloudprint";
     18 const char kTestPageURL[] =
     19     "http://www.google.com/landing/cloudprint/enable.html?print=true";
     20 
     21 void CloudPrintURL::RegisterPreferences() {
     22   DCHECK(profile_);
     23   PrefService* pref_service = profile_->GetPrefs();
     24   if (pref_service->FindPreference(prefs::kCloudPrintServiceURL))
     25     return;
     26   pref_service->RegisterStringPref(prefs::kCloudPrintServiceURL,
     27                                    kDefaultCloudPrintServiceURL);
     28 }
     29 
     30 // Returns the root service URL for the cloud print service.  The default is to
     31 // point at the Google Cloud Print service.  This can be overridden by the
     32 // command line or by the user preferences.
     33 GURL CloudPrintURL::GetCloudPrintServiceURL() {
     34   DCHECK(profile_);
     35   RegisterPreferences();
     36 
     37   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
     38   GURL cloud_print_service_url = GURL(command_line.GetSwitchValueASCII(
     39       switches::kCloudPrintServiceURL));
     40   if (cloud_print_service_url.is_empty()) {
     41     cloud_print_service_url = GURL(
     42         profile_->GetPrefs()->GetString(prefs::kCloudPrintServiceURL));
     43   }
     44   return cloud_print_service_url;
     45 }
     46 
     47 GURL CloudPrintURL::GetCloudPrintServiceDialogURL() {
     48   GURL cloud_print_service_url = GetCloudPrintServiceURL();
     49   std::string path(cloud_print_service_url.path() + "/client/dialog.html");
     50   GURL::Replacements replacements;
     51   replacements.SetPathStr(path);
     52   GURL cloud_print_dialog_url = cloud_print_service_url.ReplaceComponents(
     53       replacements);
     54   return cloud_print_dialog_url;
     55 }
     56 
     57 GURL CloudPrintURL::GetCloudPrintServiceManageURL() {
     58   GURL cloud_print_service_url = GetCloudPrintServiceURL();
     59   std::string path(cloud_print_service_url.path() + "/manage.html");
     60   GURL::Replacements replacements;
     61   replacements.SetPathStr(path);
     62   GURL cloud_print_manage_url = cloud_print_service_url.ReplaceComponents(
     63       replacements);
     64   return cloud_print_manage_url;
     65 }
     66 
     67 GURL CloudPrintURL::GetCloudPrintLearnMoreURL() {
     68   GURL cloud_print_learn_more_url(kLearnMoreURL);
     69   return cloud_print_learn_more_url;
     70 }
     71 
     72 GURL CloudPrintURL::GetCloudPrintTestPageURL() {
     73   GURL cloud_print_learn_more_url(kTestPageURL);
     74   return cloud_print_learn_more_url;
     75 }
     76