Home | History | Annotate | Download | only in cloud_print
      1 // Copyright (c) 2012 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 #ifndef CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
      6 #define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
      7 
      8 #include <map>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/memory/scoped_ptr.h"
     13 
     14 class GURL;
     15 
     16 namespace base {
     17 class DictionaryValue;
     18 }
     19 
     20 // Helper consts and methods for both cloud print and chrome browser.
     21 namespace cloud_print {
     22 
     23 // A map representing printer tags.
     24 typedef std::map<std::string, std::string> PrinterTags;
     25 
     26 // Appends a relative path to the url making sure to append a '/' if the
     27 // URL's path does not end with a slash. It is assumed that |path| does not
     28 // begin with a '/'.
     29 // NOTE: Since we ALWAYS want to append here, we simply append the path string
     30 // instead of calling url::ResolveRelative. The input |url| may or may not
     31 // contain a '/' at the end.
     32 std::string AppendPathToUrl(const GURL& url, const std::string& path);
     33 
     34 GURL GetUrlForSearch(const GURL& cloud_print_server_url);
     35 GURL GetUrlForSubmit(const GURL& cloud_print_server_url);
     36 GURL GetUrlForPrinterList(const GURL& cloud_print_server_url,
     37                           const std::string& proxy_id);
     38 GURL GetUrlForPrinterRegistration(const GURL& cloud_print_server_url);
     39 GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url,
     40                             const std::string& printer_id);
     41 GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url,
     42                             const std::string& printer_id,
     43                             const std::string& reason);
     44 GURL GetUrlForJobFetch(const GURL& cloud_print_server_url,
     45                        const std::string& printer_id,
     46                        const std::string& reason);
     47 GURL GetUrlForJobCjt(const GURL& cloud_print_server_url,
     48                      const std::string& job_id,
     49                      const std::string& reason);
     50 GURL GetUrlForJobDelete(const GURL& cloud_print_server_url,
     51                         const std::string& job_id);
     52 GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url,
     53                               const std::string& job_id,
     54                               const std::string& status_string,
     55                               int connector_code);
     56 GURL GetUrlForUserMessage(const GURL& cloud_print_server_url,
     57                           const std::string& message_id);
     58 GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url,
     59                           const std::string& oauth_client_id,
     60                           const std::string& proxy_id);
     61 
     62 // Parses the response data for any cloud print server request. The method
     63 // returns null if there was an error in parsing the JSON. The succeeded
     64 // value returns the value of the "success" value in the response JSON.
     65 // Returns the response as a dictionary value.
     66 scoped_ptr<base::DictionaryValue> ParseResponseJSON(
     67     const std::string& response_data,
     68     bool* succeeded);
     69 
     70 // Returns the MIME type of multipart with |mime_boundary|.
     71 std::string GetMultipartMimeType(const std::string& mime_boundary);
     72 
     73 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits).
     74 void CreateMimeBoundaryForUpload(std::string *out);
     75 
     76 // Returns an MD5 hash for |printer_tags| and the default required tags.
     77 std::string GetHashOfPrinterTags(const PrinterTags& printer_tags);
     78 
     79 // Returns the post data for |printer_tags| and the default required tags.
     80 std::string GetPostDataForPrinterTags(
     81     const PrinterTags& printer_tags,
     82     const std::string& mime_boundary,
     83     const std::string& proxy_tag_prefix,
     84     const std::string& tags_hash_tag_name);
     85 
     86 // Get the cloud print auth header from |auth_token|.
     87 std::string GetCloudPrintAuthHeader(const std::string& auth_token);
     88 
     89 }  // namespace cloud_print
     90 
     91 #endif  // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_
     92