Home | History | Annotate | Download | only in common
      1 // Copyright 2013 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 COMPONENTS_TRANSLATE_COMMON_TRANSLATE_METRICS_H_
      6 #define COMPONENTS_TRANSLATE_COMMON_TRANSLATE_METRICS_H_
      7 
      8 #include <string>
      9 
     10 #include "base/time/time.h"
     11 
     12 namespace translate {
     13 
     14 // An indexing type to query each UMA entry name via GetMetricsName() function.
     15 // Note: |kMetricsEntries| should be updated when a new entry is added here.
     16 enum MetricsNameIndex {
     17   UMA_LANGUAGE_DETECTION,
     18   UMA_CONTENT_LANGUAGE,
     19   UMA_HTML_LANG,
     20   UMA_LANGUAGE_VERIFICATION,
     21   UMA_TIME_TO_BE_READY,
     22   UMA_TIME_TO_LOAD,
     23   UMA_TIME_TO_TRANSLATE,
     24   UMA_USER_ACTION_DURATION,
     25   UMA_PAGE_SCHEME,
     26   UMA_SIMILAR_LANGUAGE_MATCH,
     27   UMA_MAX,
     28 };
     29 
     30 // A page may provide a Content-Language HTTP header or a META tag.
     31 // TranslateHelper checks if a server provides a valid Content-Language.
     32 enum LanguageCheckType {
     33   LANGUAGE_NOT_PROVIDED,
     34   LANGUAGE_VALID,
     35   LANGUAGE_INVALID,
     36   LANGUAGE_MAX,
     37 };
     38 
     39 // When a valid Content-Language is provided, TranslateHelper checks if a
     40 // server provided Content-Language matches to a language CLD determined.
     41 enum LanguageVerificationType {
     42   LANGUAGE_VERIFICATION_CLD_DISABLED,  // obsolete
     43   LANGUAGE_VERIFICATION_CLD_ONLY,
     44   LANGUAGE_VERIFICATION_UNKNOWN,
     45   LANGUAGE_VERIFICATION_CLD_AGREE,
     46   LANGUAGE_VERIFICATION_CLD_DISAGREE,
     47   LANGUAGE_VERIFICATION_TRUST_CLD,
     48   LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE,
     49   LANGUAGE_VERIFICATION_MAX,
     50 };
     51 
     52 // Scheme type of pages Chrome is going to translate.
     53 enum SchemeType {
     54   SCHEME_HTTP,
     55   SCHEME_HTTPS,
     56   SCHEME_OTHERS,
     57   SCHEME_MAX,
     58 };
     59 
     60 // Called after TranslateHelper verifies a server providing Content-Language
     61 // header. |provided_code| contains a Content-Language header value which a
     62 // server provides. It can be empty string when a server doesn't provide it.
     63 // |revised_code| is a value modified by format error corrector.
     64 void ReportContentLanguage(const std::string& provided_code,
     65                            const std::string& revised_code);
     66 
     67 // Called after TranslateHelper verifies a page providing html lang attribute.
     68 // |provided_code| contains a html lang attribute which a page provides. It can
     69 // be empty string when a page doesn't provide it. |revised_code| is a value
     70 // modified by format error corrector.
     71 void ReportHtmlLang(const std::string& provided_code,
     72                     const std::string& revised_code);
     73 
     74 // Called when CLD verifies Content-Language header.
     75 void ReportLanguageVerification(LanguageVerificationType type);
     76 
     77 // Called when the Translate Element library is ready.
     78 void ReportTimeToBeReady(double time_in_msec);
     79 
     80 // Called when the Translate Element library is loaded.
     81 void ReportTimeToLoad(double time_in_msec);
     82 
     83 // Called when a page translation is finished.
     84 void ReportTimeToTranslate(double time_in_msec);
     85 
     86 // Called when a translation is triggered.
     87 void ReportUserActionDuration(base::TimeTicks begin, base::TimeTicks end);
     88 
     89 // Called when a translation is triggered.
     90 void ReportPageScheme(const std::string& scheme);
     91 
     92 // Called when CLD detects page language.
     93 void ReportLanguageDetectionTime(base::TimeTicks begin, base::TimeTicks end);
     94 
     95 // Called when CLD agreed on a language which is different, but in the similar
     96 // language list.
     97 void ReportSimilarLanguageMatch(bool match);
     98 
     99 // Gets UMA name for an entry specified by |index|.
    100 const char* GetMetricsName(MetricsNameIndex index);
    101 
    102 }  // namespace translate
    103 
    104 #endif  // COMPONENTS_TRANSLATE_COMMON_TRANSLATE_METRICS_H_
    105