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

Unified Diff: chrome/browser/google_apis/operations_base.cc

Issue 10963038: drive: Set a custom User-Agent header for Drive operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/google_apis/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/google_apis/operations_base.cc
diff --git a/chrome/browser/google_apis/operations_base.cc b/chrome/browser/google_apis/operations_base.cc
index 076ac3e0f184d194312aa22235779dcf6e0728ad..1df2506203a8547e2c62202a3b7a049b2bc3b121 100644
--- a/chrome/browser/google_apis/operations_base.cc
+++ b/chrome/browser/google_apis/operations_base.cc
@@ -10,6 +10,7 @@
#include "base/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/common/net/url_util.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_urls.h"
@@ -19,6 +20,7 @@
#include "net/http/http_util.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
+#include "webkit/user_agent/user_agent_util.h"
using content::BrowserThread;
using net::URLFetcher;
@@ -62,6 +64,33 @@ void ParseJsonOnBlockingPool(const std::string& data,
}
}
+// Returns a user agent string used for communicating with the Drive backend,
+// both WAPI and Drive API. The user agent looks like:
+//
+// chromedrive-<VERSION> chrome-cc/none (<OS_CPU_INFO>)
+// chromedrive-24.0.1274.0 chrome-cc/none (CrOS x86_64 0.4.0)
+//
+// TODO(satorux): Move this function to somewhere else: crbug.com/151605
+std::string GetDriveUserAgent() {
+ const char kDriveClientName[] = "chromedrive";
+
+ chrome::VersionInfo version_info;
+ const std::string version = (version_info.is_valid() ?
+ version_info.Version() :
+ std::string("unknown"));
+
+ // This part is <client_name>/<version>.
+ const char kLibraryInfo[] = "chrome-cc/none";
+
+ const std::string os_cpu_info = webkit_glue::BuildOSCpuInfo();
+
+ return base::StringPrintf("%s-%s %s (%s)",
+ kDriveClientName,
+ version.c_str(),
+ kLibraryInfo,
+ os_cpu_info.c_str());
+}
+
} // namespace
namespace gdata {
@@ -182,6 +211,10 @@ void UrlFetchOperationBase::Start(const std::string& auth_token) {
// Note that SetExtraRequestHeaders clears the current headers and sets it
// to the passed-in headers, so calling it for each header will result in
// only the last header being set in request headers.
+ //
+ // TODO(satorux): The custom user-agent should be set only for Drive
+ // operations. crbug.com/151605
+ url_fetcher_->AddExtraRequestHeader("User-Agent: " + GetDriveUserAgent());
url_fetcher_->AddExtraRequestHeader(kGDataVersionHeader);
url_fetcher_->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, auth_token.data()));
« no previous file with comments | « chrome/browser/google_apis/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698